2013-03-23 101 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扩展和完美的作品。

相关问题