user3463981
user3463981

Reputation: 29

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.

Upvotes: 1

Views: 3111

Answers (3)

Mohamed Belal
Mohamed Belal

Reputation: 622

try this

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

Upvotes: 0

Saty
Saty

Reputation: 22532

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]

Upvotes: 1

Nikolaj Sarry
Nikolaj Sarry

Reputation: 243

You can try this

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

Upvotes: 1

Related Questions