2013-12-12 30 views
0

我想.htaccess文件,以便能夠處理可選尾隨斜線,這樣既[阿帕奇] [的.htaccess]可選尾隨斜線

localhost/Stuff/Test 
localhost/Stuff/Test/ 

會工作。我搜索了一個答案,但我發現的是我需要'/?',而且我已經提供了這個答案。幫幫我?這裏是我的.htaccess文件:

<IfModule mod_rewrite.c> 
RewriteEngine On # Turn on the rewriting engine 

RewriteCond %{REQUEST_URI} !\.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([a-zA-Z0-9]+)/?$ $1.php [NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* custom_404.html [L] 

</IfModule> 

目前它只能在沒有斜線的情況下工作。

回答

0

嘗試THI代碼PHP擴展隱藏:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule^custom_404.html [L] 
+0

沒有運氣。我想到我的問題可能是後面的斜槓導致重定向的URL並排兩個斜槓,所以我會研究它。 – TakingItCasual

+0

你有沒有其他規則也沒有在上面顯示或其他.htaccess在你的系統? – anubhava

+0

我已經展示了整個.htaccess文件,並且在xampp目錄中似乎還有一些.htaccess文件 – TakingItCasual