我有一个网站使用apache mod_rewrite
,并且一直在过去6个月没有错误的工作。Apache mod_rewrite没有将表达式映射到参数
我有以下重写规则:
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\-]+)
映射到category=$1
?
额外的信息
我注意到.htaccess
文件的主机上已经注释掉线Options +FollowSymLinks
所以我第一次尝试重新启用这个只有拥有该网站返回一个Apache白色屏幕500
错误。从.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>
你是什么意思重写的意思是发生? products.php脚本仍然被调用? – 2013-04-24 00:20:44
是的,没有400错误,脚本仍然退出products.php – samazi 2013-04-24 00:22:15
您不需要在字符类中跳过连字符。只要把它放在第一或最后,例如'[a-z-]' – Phil 2013-04-24 00:26:47