Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Redirect Subdomain to Main Site Domain

Submitted by on May 14, 2010 – 8:14 amNo Comment

Site was available through sub domain (for example, its test version), and you need to move it to server root.  To avoid content duplicating (search engines don’t like this) you should canonize domain name (redirecting  "www.example.com" → "example.com").

We will use the following ways to redirect subdomain to main site domains:

  • Using of .htaccess file
  • Using of Toggle WWW module

Using of .htaccess file

Find .htaccess file (it is at the end of site root) and add this:

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

After this code:

<IfModule mod_rewrite.c>
  RewriteEngine on

How such redirecting works:

 

Using of Toggle WWW

An easy, PHP header redirect based way to redirect incoming links from http://www.example.com/some/deep/page to http://example.com/some/deep/page or vice-versa.

Intended for use on servers without Apache servers, hosts where .htaccess is not allowed, etc. Apache directives based redirects are faster than PHP based methods. It is a known caveat that it does not redirect to the correct URL when access is denied to a page; because drupal prompts for the access before the module is even loaded.

The advantages of this method:

  • There is no waste of links weight (search engines pass weight to a new page)
  • Old links still work

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.