Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect + hide subfolder in url

I've looked around and have attempted some rules and conditions that worked; while some did not work or the condition would capture too much causing other domains to also redirect. This works for me:

# Redirect (also catches www.)
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder [L]

resulting in if you visit www.domain.com OR domain.com being redirected to domain.com/subfolder Great, but I'dd also like the /subfolder part to be hidden from the url.

How do I achieve this ?

Note that I have multiple domains, each should redirect to its own folder. I also want each page to still be visible in its respective folder.

So www.domain.com/abc should redirect to domain.com/subfolder/abc but show domain.com/abc

like image 700
Zerreth Avatar asked Jan 07 '14 18:01

Zerreth


1 Answers

Try this rule:

# remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule !^subfolder/ /subfolder%{REQUEST_URI}  [L]
like image 112
anubhava Avatar answered Oct 13 '22 13:10

anubhava