简体   繁体   中英

how to hide folder name from url using .htaccess

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.

You can try this

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

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]

try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM