Apache htaccess隐藏.php和.html扩展名

Apache htaccess隐藏.php和.html扩展名,apache,.htaccess,mod-rewrite,url-rewriting,rewrite,Apache,.htaccess,Mod Rewrite,Url Rewriting,Rewrite,我应该添加哪些行来从我的站点中删除.html和.php扩展 我仅将其用于.html部分: RewriteEngine on RewriteBase / RewriteCond %{http://jobler.ro/} !(\.[^./]+)$ RewriteCond %{REQUEST_fileNAME} !-d RewriteCond %{REQUEST_fileNAME} !-f RewriteRule (.*) /$1.html [L] RewriteCond %{THE_REQUEST

我应该添加哪些行来从我的站点中删除
.html
.php
扩展

我仅将其用于
.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]

但是我需要在同一个域中隐藏两个文件类型扩展名。

您需要测试带有
.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]

我知道回答这个问题很晚,但我还是给出了答案,因为它可能对某人有用:)


这将从您的文件中删除php和html扩展名,效果非常好。

谢谢。工作完美@Blazer,嘿,既然一切正常,你有没有机会点击接受答案?:-)@Blazer,既然这很好用,你有没有可能点击“接受”按钮,这样你和我都能得到辛苦工作的分数?谢谢
#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