2012-12-22 84 views
1

這是我原來的鏈接htaccess的規則不起作用

http://localhost/xx/xx/public_html/news.php?id=7 

我想將其更改爲

http://localhost/xx/xx/public_html/news-7-TitleOfNews.html 

,這裏是我的htaccess

Options -Indexes 
ErrorDocument 404 www.site.com/404.html 
RewriteEngine On 
RewriteRule ^news-([0-9]*)(?:-([0-9a-zA-Z*]))?(?:\.html)?$ news.php?id=$1 [L] 

,但它不工作(重定向到404頁)

+0

你有服務器上的'Mod_rewrite'激活嗎? – Disa

回答

3

我想你是在尋找這樣的:

RewriteRule ^news-([0-9]*)(?:-[0-9a-zA-Z]*)?(?:\.html)?$ news.php?id=$1 [L] 

的區別在於*量詞應該是字符類表達的外部。並且將單個字符類包裝爲括號是多餘的。