Remove all folder name form url

☆樱花仙子☆ 提交于 2021-02-05 09:18:30

问题


Recently I have installed my site into a sub-folder of root of server.

So To remove folders name from URL i have used following htaccess code.

Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?hostname.com$
RewriteRule ^(/)?$ user/site1/index.php [L] 

But the problem is that i am, also able to access my site Via

hostname.com/user/site1

How can i stop user accessing my site via "hostname.com/user/site1"

Please help


回答1:


You can have a new redirect rule for this:

Options -Indexes
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} /user/site1(\S*)\s [NC]
RewriteRule ^ %1 [R=302,L,NE]

RewriteCond %{HTTP_HOST} ^(www\.)?hostname\.com$
RewriteRule ^/?$ user/site1/index.php [L] 


来源:https://stackoverflow.com/questions/28281147/remove-all-folder-name-form-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!