2011-12-08 93 views
-1

可能重複:
How to remove .php extension and add slash on the url?重寫規則以刪除「.php」擴展名並添加尾部斜槓?

我需要把我的.htacces(也就是現在的空白)的東西,從我所有的網址刪除.php然後還強制尾隨削減。


我知道問題的這種(通常的方式更具體)已被要求numerouse次,但我發誓,我無法找到答案爲我工作。

奇怪的是,我曾經有一個.htaccess代碼來做我想做的事,我發誓我從這裏得到了代碼......但是我失去了它。

+0

http://stackoverflow.com/questions/4858253/how-to-remove-php-extension-and-add-slash-on-the- url,http://stackoverflow.com/questions/3133111/mod-rewrite-add-trailing-slash,http://stackoverflow.com/questions/3321214/how-to-remove-all-php-extension-from- a-dir及其所有子目錄 – 2011-12-08 23:49:56

+0

......我們走了。 – 2011-12-08 23:50:44

+0

@DigitalPrecision他沒有使用symfony,這有什麼關係? – Flukey

回答

1

嘗試添加在你的域

RewriteEngine On 
RewriteBase/

#skip existing files and directories 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
#capture every url path request ending with a slash 
RewriteCond %{REQUEST_URI} /(.+)/$ [NC] 
#and rewritten to .php with that name. Assumes all .php files are in the root 
RewriteRule . %1.php [NC,L]  


#add a trailing slash to all urls without one 
RewriteCond %{REQUEST_URI} ^(/.+[^/]) [NC] 
RewriteRule . %1/ [L,R=301] 

#remove .php from all urls and also add a trailing slash 
RewriteRule (.*)\.php /$1/ [L,R=301,NC] 

編輯根以下到.htaccess文件: 上述修改重寫用斜槓a.php只會相同名稱的後綴路徑的請求。請注意,這假定所有.php文件都在根目錄中

+0

是爲了? - 因爲我的htaccess是這樣寫的,IE,FF;他們甚至不會去我的網頁。 – user1086506

+0

好的我寫了:RewriteEngine On RewriteBase/RewriteCond%{REQUEST_URI} ^(/.+ [^ /])[NC] RewriteRule(。*)\。php/$ 1/[L,R = 301,NC]工程(removes.php並添加尾部斜線),但我得到了404。我不想這樣。我該怎麼辦? – user1086506

+0

http://stackoverflow.com/questions/1068595/htaccess-code-to-remove-extension-and-addforce-trailing-slash[/link]是答案的地方。不管怎麼說,多謝拉 – user1086506

相關問題