Mobile app version of vmapp.org
Login or Join
Correia994

: Subfolder non-www redirect 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/

@Correia994

Posted in: #301Redirect #Apache #Htaccess #Redirects

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 ^(.*)$ %1/ [R=301,L]


but this only redirects the example.com to example.com.

I would like to redirect:
example.com/home/ to example.com/home/
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 ^$ example.com [R=301,L]

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/home/ [NC]
RewriteRule ^(.+)$ example.com/ [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 ^(.*)$ example.com/subfoldername/ [R=301,L]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Correia994

1 Comments

Sorted by latest first Latest Oldest Best

 

@Kevin317

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

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme