2013-03-23 126 views
2

我應該添加哪些行以從我的網站中刪除.html.php擴展名?Apache .htaccess隱藏.php和.html擴展

我用這個只是.html部分:

RewriteEngine on 

RewriteBase/
RewriteCond %{http://jobler.ro/} !(\.[^./]+)$ 
RewriteCond %{REQUEST_fileNAME} !-d 
RewriteCond %{REQUEST_fileNAME} !-f 
RewriteRule (.*) /$1.html [L] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP 
RewriteRule ^([^.]+)\.html$ http://jobler.ro/$1 [R=301,L] 

,但我需要兩個文件類型擴展名從同一個域隱藏。

回答

2

你會想測試是否存在帶有.html.php的文件,如果存在,則重定向到這樣的文件。

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.*)$ $1.html [L] 

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

RewriteCond %{REQUEST_URI} \.((html)|(php))$ 
RewriteRule ^(.*)\.([^.]+)$ $1 [R,L] 
+0

謝謝。完美的作品! – Blazer 2013-03-24 14:23:01

+0

@Blazer,嘿,因爲它一切正常,你有什麼機會點擊接受答案? :-) – cnst 2016-02-02 23:17:53

+0

@Blazer,因爲這個工作非常好,任何機會你都可以點擊接受按鈕,這樣你和我都能得到努力工作的積分?謝謝! – cnst 2016-07-03 06:22:14

3

我知道它來不及回答,但我給它,因爲它可能是有用的人:)

#Remove php extension 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^(.*)$ $1.php 

#Remove html extension 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.html -f 
    RewriteRule ^(.*)$ $1.html 

這將從文件中刪除PHP和HTML擴展和完美的作品。