iSaumya
iSaumya

Reputation: 1623

htaccess code for redirecting sub folder to the root domain without affecting other sub domain

The issue is in my public_html directory I have a www7 folder, which I used as a root domain link. Like if anyone visit example.com or www.example.com it redirects it to www7.example.com. For this I have used this below htaccess code:

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

I also have many other sub domains under public_html like, sub1.exaple.com , sub2.exaple.com. Now I want that tough my main files are present in www7 folder, whenever anyone open exaple.com it will actually openup the files inside www7 folder, but have to make sure that the other sub domains under public html should not get affected. Also in the www7 folder a wordpress site has been hosted, so it needs to be wordpress friendly too. Also if anybody open www.exaple.com it will redirect him to exaple.com. I think for this, the below code will work

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

But not sure about the directory issue. Please help.

Upvotes: 1

Views: 455

Answers (1)

anubhava
anubhava

Reputation: 785286

You have this rule in root .htaccess:

RewriteCond %{HTTP_HOST} ^isaumya\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.isaumya\.com$
RewriteRule ^/?$ "http\:\/\/www8\.isaumya\.com\/" [R=301,L]

Replace this rule with:

RewriteRule !^www8/ /www8%{REQUEST_URI} [L,NC]

Upvotes: 1

Related Questions