使用Htaccess删除文件夹名称

用户名

我认为htaccess代码中存在一些问题,但我无法弄清楚。

我需要的是。

1)从www.domain.com/index之类的地址中删除.php扩展名,而不是www.domain.com/index.php之类的

2)删除文件夹名称。我的网站文件存储在一个名为public的文件夹中。我要删除它。www.domain.com/public/index.php到www.domain.com/index

我写了下面的代码,请让我知道这有什么问题。

# This will hide the folder name public and the php text
Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+public/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
# if you face any problem than try to uncomment the below line and delete the line after it
RewriteRule (?!^public/)^(.*)$ public/$1 [L,NC]
阿努巴瓦

您可以具有如下规则:

# This will hide the folder name public and the php text
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+public/(\S+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
# if you face any problem than try to uncomment the below line and delete the line after it
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/public/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章