0

我正在处理我网站的 htaccess。

我有这段.htacess:

ErrorDocument 404 /404.html

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f


RewriteRule ^/([a-zA-z0-9]+)/([a-zA-z0-9]+).html$ index.php?lang=$2&seo=$1 [QSA,L]

RewriteRule ^/([a-zA-z0-9]+).html$ index?seo=$1 [QSA,L]

我在看这个 .htaccess 的内容是:http://mywebsite.com/en/test-page.htmlhttp://mywebsite.com/index.php?lang=en&seo=test-page“en”计数为“lang”,将“test-page”计数为“seo”。

问题是这会引发 404 错误。

有没有办法来解决这个问题?

4

2 回答 2

0

试试这个,我认为问题index?seo在于必须是index.php?seo跳过标志,如果你S=1在模式匹配时放置它,在它之后跳过一个 RewriteRule

 RewriteRule ^/([a-zA-z0-9]+)/([a-zA-z0-9]+).html$ index.php?lang=$1&seo=$2 [S=1,QSA,L]

 RewriteRule ^/([a-zA-z0-9]+).html$ index.php?seo=$1 [QSA,L]

如果你想通过查询也使用这个

 RewriteRule ^/([a-zA-z0-9]+)/([a-zA-z0-9]+).html(.*)$ index.php?lang=$1&seo=$2$3 [S=1,QSA,L]

 RewriteRule ^/([a-zA-z0-9]+).html(.*)$ index.php?seo=$1$2 [QSA,L]
于 2013-05-13T14:46:36.873 回答
0

尝试从您的正则表达式中删除前导斜杠:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ index.php?lang=$1&seo=$2 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-z0-9]+)\.html$ index.php?seo=$1 [QSA,L]

另外,请记住,这RewriteCond仅适用于一个RewriteRule.

于 2013-05-13T14:56:39.537 回答