我有一个网站使用apache mod_rewrite
并且在过去 6 个月里一直工作,没有出现任何错误。
我有以下重写规则:
RewriteRule ^products/([a-z\-]+)/$ /products.php?category=$1 [NC,L]
这是我页面中的代码products.php
$category = $_GET['category'];
if (isset($category)) {
// do some processing here
}
else {
header("Location: /500.html");
exit;
}
符合此规则的链接的示例是/products/lighting-poles/
有谁知道为什么实际重写仍在发生但没有映射([a-z\-]+)
to category=$1
?
额外信息
我注意到.htaccess
主机上的文件已注释掉该行Options +FollowSymLinks
所以我首先尝试重新启用此功能,结果网站返回 apache 白屏500
error.
.htaccess 文件的更多内容
<IfModule mod_rewrite.c>
#Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]
# other rules including problem rule here
</IfModule>
这听起来像一个病态的多视图问题。多视图是一种内容协商功能,如果打开它,它将在 URL 文件映射管道中尝试一些不同的额外操作,以尝试查找映射到 URL 的文件。这里你有一个像这样的网址/products/blah
,但是,你有一个名为products.php
,所以多视图可能会尝试映射products
to /products.php/blah
。因此完全绕过重写规则,并且您看不到category
范围。
在选项所在的位置,尝试添加:
Options -Multiviews
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)