我有一個網站,所有頁面都是php腳本,所以URL結束.php。使用mod_rewrite從URL末尾隱藏.php
我添加以下到.htaccess文件,現在我可以訪問.php文件不帶.php擴展名:
RewriteEngine On # Turn on rewriting
RewriteCond %{REQUEST_FILENAME}.php -f # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php # serve the PHP file
到目前爲止好。但是現在我想在所有的.php文件上添加一個重定向,這樣我的控制之外的任何舊鏈接都會被重定向到新版本的URL。
我已經試過這樣:
RewriteEngine On # Turn on rewriting
RewriteCond %{REQUEST_URI} .*\.php
RewriteRule ^(.*)\.php$ http://example.com/$1 [R=permanent,L]
RewriteCond %{REQUEST_FILENAME}.php -f # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php [L] # serve the PHP file
,但似乎發送重定向即使對於不以.php結尾的URL,讓我陷入無限循環。我嘗試的任何其他組合似乎都不匹配任何請求(並留下我在page.php)或所有請求(並讓我陷入循環)。
檢出http://stackoverflow.com/questions/3024631/htaccess-remove-php-extension-index-php-and-add-trailing-slash/ – TheDeadMedic 2010-06-21 16:21:08