.htaccess - 从URL中删除目录和扩展名

时间:2016-11-27 21:50:13

标签: .htaccess

我的网址如下所示:

example.com/live/file1.php

所以,我希望用户像这样访问它:

example.com/file1

我已将此添加到.htaccess文件中:

RewriteRule ^(?!live/)(.*)$ live/$1 [L,NC]

...这对于live文件夹:

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

我认为它有效,但我希望在访问.php时隐藏example.com/file1.php扩展名。

这是正确的方法吗?

1 个答案:

答案 0 :(得分:1)

RewriteEngine On
RewriteRule ^$ live/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ live/$1




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