我有一個網站使用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