.htaccess ModReWrite help

删除回忆录丶 提交于 2020-01-06 07:58:09

问题


I am having some trouble with my ReWrite code. Please note that the .htaccess file is in the subdomain folder (...public_html/subdomain/ )

I am simply trying to rewrite a page request:

http://subdomain.mysite.com/home
http://subdomain.mysite.com/index.php?page=home

My .htaccess file looks like this...

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_])$ /index.php?page=$1

Does anything jump out at you?


回答1:


Your current rule probably works for urls one character long (after the slash)!

Add a + to signify one or more characters, or a * for zero or more

Try

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\-\_]*)$ /index.php?page=$1



回答2:


If you want to use the rules in a .htaccess file, you need to strip the contextual per-directory path prefix from the RewriteRule pattern. If the .htaccess file is located in the document root /, you need to strip the leading /.

Additionally you need to quantify the character set. Otherwise it would only describe one character.

So try this rule:

RewriteRule ^([A-Za-z0-9-_]+)$ index.php?page=$1



回答3:


I think

RewriteRule ^([^/]*)$ /index.php?page=$1 [L]

is ok ;)



来源:https://stackoverflow.com/questions/912037/htaccess-modrewrite-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!