使用Htaccess删除文件夹名称(Remove folder name using Htaccess)
我认为我的htaccess代码存在一些问题,但我无法弄明白。
我需要的是。
1)从地址中删除.php扩展名,例如www.domain.com/index而不是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]I think there is some problem in my htaccess code but I cannot able to figure out.
What I need is.
1) Remove .php extension from the address like www.domain.com/index instead of www.domain.com/index.php
2) Remove the folder name. My website files store in a folder called public. I want to remove it. www.domain.com/public/index.php to www.domain.com/index
I wrote the below code, please let me know whats wrong in this.
# 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]You can have your rules like this:
# 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]更多推荐
发布评论