how to hide folder name from url using .htaccess

こ雲淡風輕ζ 提交于 2020-01-11 11:52:07

问题


I have a domain example.com i want to redirect it to example.com/public but /public folder should hide from the url.

I am using the below code in .htaccess to redirect, but unable to hide the folder name

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$

RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteRule ^$ public [L]

Please help me out for this issue.


回答1:


You can try this

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(public)
RewriteRule (.*) /public/$1



回答2:


This should be your complete .htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+dirname/([^\s]+) [NC]// here you write your directory
RewriteRule ^ %1 [R=301,L]

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



回答3:


try this

RewriteEngine On    
RewriteRule (.*) public/$ [QSA,L]  


来源:https://stackoverflow.com/questions/30323876/how-to-hide-folder-name-from-url-using-htaccess

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