我正在使用以下 .htaccess 代码:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA]
RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA]
RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA]
为了达到如下效果:
http://xyz.com/ca/test -> http://xyz.com/index.php?p=test&c=ca
http://xyz.com/fr/test -> http://xyz.com/index.php?p=test&c=fr
http://xyz.com/test -> http://xyz.com/index.php?p=test
但由于服务器错误而失败。关于如何修复它有什么想法吗?
谢谢
最佳答案
RewriteCond
条件仅适用于紧随该条件的 RewriteRule
。您的最后 2 条规则没有任何条件,并且规则正在循环。只需在最后 2 条规则前面添加 2 个条件即可:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA]
关于apache - .htaccess RewriteRule 国家/地区代码和 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12171282/