how to hide folder name from url using .htaccess

2020-04-28 09:22发布

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.

3条回答
Bombasti
2楼-- · 2020-04-28 09:43

try this

RewriteEngine On    
RewriteRule (.*) public/$ [QSA,L]  
查看更多
forever°为你锁心
3楼-- · 2020-04-28 09:44

You can try this

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(public)
RewriteRule (.*) /public/$1
查看更多
相关推荐>>
4楼-- · 2020-04-28 10:01

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]
查看更多
登录 后发表回答