Home Ask Login Register

Developers Planet

Your answer is one click away!

Willem February 2016

Redirect All Subdomain URLs to Home Page

The website in question had a sub domain for the eCommerce platform, but now we've added the eCommerce functionality to the main site, so now we want to entire shop sub domain to redirect to the home page. Currently I'm using the following code in the .htaccess file:

RewriteCond %{HTTP_HOST} ^shop.domain.co.za$ [NC]
RewriteRule ^(.*)$ http://www.domain.co.za%{REQUEST_URI} [R=301,NC,L,QSA]

This redirects any URL on the sub domain to that same URL on the main site, so shop.domain.co.za/product will redirect to www.domain.co.za/product, but we want it to redirect to home page, since the URL structure has completely changed.

So in other words, we want any URL on shop.domain.co.za to rediect to the home page, www.domain.co.za, how can this be done?

Any help would be greatly appreciated.



anubhava February 2016

You can replace your rule with this rule:

RewriteCond %{HTTP_HOST} =shop.domain.co.za
RewriteRule ^ http://www.domain.co.za/? [R=301,L]

Using %{REQUEST_URI} will cause original URI to be copied in target. Trailing ? in target will strip off any pre-existing query string.

Post Status

Asked in February 2016
Viewed 3,005 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life