2015-11-30 23 views
2

我想重寫如何使用的.htaccess

www.example.com/story.php?id=123&title=abc&cat=sports 

www.example.com/story/123?title=abc&cat=sports 

刪除的文件擴展名(.php)和我已經使用

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

它不工作。

回答

1
RewriteEngine On 
RewriteCond %{THE_REQUEST} ^GET\ /(story)\.php\?id=(\d+)&(\S+) [NC] 
RewriteRule ^story\.php$ /%1/%2?%3 [R=301,L] 

RewriteRule ^(story)/(\d+)/?$ /$1.php?id=$2 [L,QSA] 

上述規則應該按需要工作。

+0

我試過這個,但它顯示「請求的URL /story.php在此服務器上沒有找到。」並且我在「http://htaccess.madewithlove.be/」中測試了它,它顯示錯誤「RewriteCond%{THE_REQUEST}^GET \ /(story)\.php\?id=(\d+)&(\S+) [NC] \t不支持此變量:%{THE_REQUEST}「。請幫忙。 – ghost

+0

@ghost提供目錄結構。 'story.php'文件位於何處?你在哪裏把htaccess文件 ? – hjpotter92

+0

htaccess和story.php都在根目錄下。 – ghost