2012-03-18 62 views
0

今天我想要實現這一點,.htaccess會自動從瀏覽器的url中刪除任何類型的文件擴展名。 比方說,例如用戶點擊一個鏈接,將用戶引導至
mylink.php
應該帶他那裏,但除去.PHP
刪除文件擴展名apache服務器



我試着使用一些代碼的.htaccess,但他們沒有太多的工作。

此外,我可以訪問該頁面,像這樣

  • 本地主機/註冊< <這一項工作正常,但我想擴展到被刪除自動
  • 本地主機/註冊/ < <這一個失去所有的造型,因爲它像在新的文件夾頁
  • 的的.htaccess代碼是

    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.html -f 
    RewriteRule ^([^/]+)/$ $1.html 
    
    # Forces a trailing slash to be added 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
    RewriteRule (.*)$ /$1/ [R=301,L] 
    

    任何想法的人嗎?

    +0

    *什麼*'.htaccess'你試過的東西?顯示您擁有的實際代碼。 – Amber 2012-03-18 21:01:47

    +0

    uodated它,隊友... – 2012-03-18 21:03:00

    +0

    [自己動手通用頁眉/ footer.php]的可能重複(http://stackoverflow.com/questions/9215791/do-it-yourself-universal-header-footer- php) – hakre 2012-03-18 21:20:42

    回答

    0
    RewriteEngine On 
    
    # Change this to the appropriate base (probably just/in your case) 
    RewriteBase /stackoverflow/9762238/ 
    
    # Any url that requests a .php file on the base will be redirected to dir with same base name 
    # The condition is important to prevent redirect loops! 
    RewriteCond %{ENV:REDIRECT_STATUS} !=200 
    RewriteRule ^(.*)\.php$ $1/ [R=301,L] 
    
    # Requests for directories that do not actually exist will be be translated into php file requests 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule (.+)/$ $1 [L]