1

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
  • A redirect or a rewrite? Commented May 19, 2015 at 11:08

3 Answers 3

1

You can try this

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(public)
RewriteRule (.*) /public/$1
Sign up to request clarification or add additional context in comments.

Comments

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]

1 Comment

Any it work :D but what to do when you have a subfolder? public/hello/world.php ?? if I write /hello/world I get a error
0

try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.