Quantcast
Channel: Eureka! » Apache
Viewing all articles
Browse latest Browse all 12

.htaccess – Redirect all URLs to a specific sub domain

$
0
0

Sometimes you may have multiple domains which you want to use for your website or web application. Probably you needed to park the domains on your hosting cpanel. In this case, you website or web application could be access by more than one domain which is not good for SEO and other 3rd party services may not work.

A simple way to redirect all URLs to a specific URLs is by .htaccess.

Suppose you have the following sub domains and all of them serve your website or web application.


To redirect all visitors to a specific sub domain say http://www.ykyuen.com.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^ykyuen.com$ [NC,OR]
  RewriteCond %{HTTP_HOST} ^ykyuen.com.hk$ [NC,OR]
  RewriteCond %{HTTP_HOST} ^www.ykyuen.com.hk$ [NC]
  RewriteRule ^(.*)$ http://www.ykyuen.com/$1 [L,R=301]
</IfModule>

 

Or you can use the NOT character (!)

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www.ykyuen.com$ [NC]
  RewriteRule ^(.*)$ http://www.ykyuen.com/$1 [L,R=301]
</IfModule>

 

Done =)


Filed under: Apache Tagged: .htaccess, SEO

Viewing all articles
Browse latest Browse all 12

Trending Articles