2

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 www.example.com to example.com.

I would like to redirect:

www.example.com/home/ to example.com/home/

www.example.com/home/whatever URL to example.com/home/whatever URL.

I have tried this:

RewriteEngine on
Options +FollowSymlinks -MultiViews

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

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

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

ANSWER

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 ^(.*)$ http://example.com/subfoldername/$1 [R=301,L]
1
  • this code is not correct RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$ RewriteRule ^(.*)$ http://example.com/subfoldername/$1 [R=301,L] this redirect internal URL to homepage. Commented Nov 6, 2014 at 9:45

1 Answer 1

1

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

RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$
RewriteRule ^(.*)$ http://example.com/subfoldername/$1 [R=301,L]

Your Answer

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

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