Tallboy
Tallboy

Reputation: 13417

how do i redirect only root using htaccess?

I currently have a subdomain i need to keep in tact: www.sub.domain.com

I also have a sub directory at www.domain.com/blog that needs to remain in tact

It's an annoying setup because I am using shopify which is 3rd party hosted using CNAMES. my shop is on shop.domain.com, and my blog is on domain.com/blog

I want to redirect ONLY root / domain.com (both www and non-www), but not if they land on anything after the / (a blog post for instance). its going to redirect to the subdomain.

This is what i have currently

ErrorDocument 404 /index.html
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Upvotes: 0

Views: 6430

Answers (3)

aldo
aldo

Reputation: 312

I have the same problem and this htaccess code is working for me

RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC] #root
RewriteRule ^$ http://www.newsite.com/news-trends/ [NC,R=301]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]  #else
RewriteRule ^(.*) http://www.newsite.com/blog/$1 [L,R]

Upvotes: 0

Riccardo Mastellone
Riccardo Mastellone

Reputation: 1

This should go!

# First we turn the rewriting engine on
RewriteEngine on

# Then we check if the host is the right one
RewriteCond %{HTTP_HOST} (www\.)?domain\.com [NC]

# Then we make sure only the home page is considered
RewriteCond %{REQUEST_URI} ^/$

# Then we redirect wherever we want!
Rewriterule ^(.*)$ http://othersite.com/ [L,R=301]

Upvotes: 0

ziesemer
ziesemer

Reputation: 28687

How about this?

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [NC]
RewriteRule ^$ <wherever you want to send the redirect> [NC,R=301]

Upvotes: 4

Related Questions