Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Is there a way to redirect a sub folder to no-www?

What I use is:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

but this only redirects the to

I would like to redirect: to URL to URL.

I have tried this:

RewriteEngine on
Options +FollowSymlinks -MultiViews

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/home/ [NC]
RewriteRule ^(.+)$$1 [R=301,L]

This does not work, either. I can't really figure it out. Any help appreciated!


I figured it out and I will post it for others to see, if having the same issue.

In the sub folder directory's .htaccess used the following:

RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$
RewriteRule ^(.*)$$1 [R=301,L]
share|improve this question
if you answered your own question please enter the answer in the answer box and click the accept button. You are allowed to accept your own answers and makes it clearer for everyone else visiting the site. –  Simon Hayter Feb 15 '13 at 16:12
this code is not correct RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$ RewriteRule ^(.*)$$1 [R=301,L] this redirect internal URL to homepage. –  Ahmad Balavipour Nov 6 '14 at 9:45

1 Answer 1

You can use the following .htaccess code for stealth sub-folder redirection:

RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$
RewriteRule ^(.*)$$1 [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.