我的网址如下所示:
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
扩展名。
这是正确的方法吗?
答案 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]