基本的 .htaccess 重写规则问题
Basic .htaccess rewrite rule issue
我正在尝试使用 .htaccess 文件设置一些规则:
我想要任何这种类型的 url: / 转发到 index.php?name=X 和任何 url with /postalcode/(anything here) 转发到 index.php?postalcode=(这里的任何东西)
这是我所做的:
RewriteRule ^([^/]*)/$ index.php?name= [L]
RewriteRule ^([^/postalcode/]*)/$ index.php?postalcode= [L]
第一个规则有效,但第二个规则无效。
有什么帮助吗?
谢谢。
让你的 .htaccess 像这样:
RewriteEngine On
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# postal code handler
RewriteRule ^postalcode/([^/]+)/?$ index.php?postalcode= [L,QSA,NC]
# name handler
RewriteRule ^([^/]+)/?$ index.php?name= [L,QSA]
我正在尝试使用 .htaccess 文件设置一些规则:
我想要任何这种类型的 url: / 转发到 index.php?name=X 和任何 url with /postalcode/(anything here) 转发到 index.php?postalcode=(这里的任何东西)
这是我所做的:
RewriteRule ^([^/]*)/$ index.php?name= [L]
RewriteRule ^([^/postalcode/]*)/$ index.php?postalcode= [L]
第一个规则有效,但第二个规则无效。 有什么帮助吗?
谢谢。
让你的 .htaccess 像这样:
RewriteEngine On
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# postal code handler
RewriteRule ^postalcode/([^/]+)/?$ index.php?postalcode= [L,QSA,NC]
# name handler
RewriteRule ^([^/]+)/?$ index.php?name= [L,QSA]