我使用一些重寫規則爲論壇創建可讀的URL。例如,如果您發佈新主題的主題爲「您對這款新車有什麼看法?」我會做這樣的鏈接:forum/cars/51-Hey-what-do-you-think-of-this-new-car-?
其中51是主題ID。使用.htacces改寫規則和特殊字符的問題
在我的.htaccess我用這個重寫規則:
RewriteEngine on
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forum/([0-9-a-z]+)/?$ forum/list_topics.php?key=$1 [L]
RewriteRule ^forum/([0-9-a-z]+)/([0-9]+)?$ forum/list_topics.php?key=$1&page=$2 [L]
RewriteRule ^forum/([0-9-a-z]+)/([0-9]+)-(.*)/?$ forum/list_post.php?topic=$2 [L]
所以這個工作正常,除非我發佈這些字符主題標題:+"*ç%&/()=?'^
我使用一個PHP函數來創建網址是:
$url_topic = str_replace(' ', '-', $url_topic); //replace space with -
$url_topic = urlencode($url_topic);//encode url
在這種情況下,$ url_topic值是:34-%2B%22%2A%C3%A7%25%26%2F%28%29%3D%3F%27%5E
,但是當我點擊它,我有以下錯誤:
Not Found
The requested URL /forum/cars/34-+"*ç%&/()=?'^ was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
我在想什麼?
感謝
嗨,感謝您的解釋,但可以添加一個我必須做的RewriteCond的例子?否則,我想我會簡單地從我的PHP字符串中刪除特殊字符。這是我認爲最好的解決方案 –