Hi Guys,
So I had this problem few weeks back and would like to share the solution with you. My dilemma was to redirect all traffic from http://www.jaspreetchahal.org to http://jaspreetchahal.org
Click here to find about Genesis Framework
This is strongly recommended by me.
There were few reasons why I wanted it to be like that. One of them was the Google Analytics stuff. GA works on per domain name basis (Correct me if I am wrong here) so tracking for jaspreetchahal.org is not same as for www.jaspreetchahal.org.
Now I had a choice to either put the tracking on for both www.jaspreetchahal.org and plain jaspreetchahal.org. I am glad that the solution was this simple.
We just need to edit our .htaccess file in the root directory of your website.
Three steps to make sure that all will work correctly
- Make sure that you Apache mod_rewrite module is available and is loaded
- Make sure that under your website directory options you have AllowOverride option set to all i.e.
<director “path/to/your/website/directory”>
AllowOrderride All
</directory> - Third is to make this change in your .htaccess file
For redirecting everything from yourdomain.com to www.yourdomain.com do this
For redirection everything from www.yourdomain.com to yourdomain.com do this- # turn on the rewrite engineRewriteEngine On
- #condition: if domain name starts with yourwebsite.com
- RewriteCond %{HTTP_HOST} ^yourwebsite.com$ [NC]
- # apply this rule: redirect the request to include www. as prefix
- RewriteRule ^(.*)$ http://www.yourwebsite.com/$1 [R=301,L] R=301 tells that its a Redirect and 301 tells that its a permanent redirect. L tells that its the last rule
- # turn on the rewrite engine
- RewriteEngine On
- #condition: if domain name starts with yourwebsite.com
- RewriteCond %{HTTP_HOST} ^www.yourwebsite.com$ [NC]
- # apply this rule: redirect the request to exclude www. as prefix.
- RewriteRule ^(.*)$ http://yourwebsite.com/$1 [R=301,L] R=301 tells that its a Redirect and 301 tells that its a permanent redirect. L tells that its the last rule
Another thing I would like to add here is that If you are not sure if mod_rewrite is available or not then its always a good idea to wrap your Rewrite code with <Ifmodule> tag as shown below
The above lines thus can be rewritten as
- <IfModule mod_rewrite.c>
- RewriteEngine On
- #condition: if domain name starts with yourwebsite.com
- RewriteCond %{HTTP_HOST} ^www.yourwebsite.com$ [NC]
- # apply this rule: redirect the request to exclude www. as prefix.
- RewriteRule ^(.*)$ http://yourwebsite.com/$1 [R=301,L] R=301 tells that its a Redirect and 301 tells that its a permanent redirect. L tells that its the last rule
- </IfModule>
After you made the above change then based on the rule you’ve used your website visitors will be directed accordingly.





JC WordPress Coupon Revealer Plugin Pro License
Australian Street Names with City, State and Display Names only, Single Server License
Recent Comments