问题
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