htaccess redirect www to non www rewriterule parameters





htaccess redirect www to non www


Htaccess redirect

Learn htaccess redirect www to non www rewriterule flags , syntax using the sample example below.

Redirect all non-www traffic

The code below will direct all traffic which does not contain the www in the URL to the same page, but now including the www. And that will clean up the canonicalization problem that arises when the www version of your site gets indexed along with the non-www version:
rewriteCond %{HTTP_HOST} ^dexterityunlimited\.com$
rewriteRule ^.*$ http://www.dexterityunlimited.com%{REQUEST_URI} [R=permanent,L]

Redirect aliases of home page to the root website

Have you noticed in your log files that people are looking for index.htm or index.asp in your root folder? Instead of letting them get a 404 Not Found error, why not direct them to your root folder, without a filename:
rewriteRule ^index\.(php|html|htm|asp) http://www.dexterityunlimited.com/ [R=permanent,L]

 

Force users to use the WWW or Non-WWW version of your domain


To avoid duplicate content in search engines you can force users to use either the www or the non-www version of your website domain. This avoids search engines such as Google indexing two versions of your domain, something which is quite common because people link to both www and on-www versions of a domain (known as the www/non-www canonical issue).
It really doesn’t matter if you use www.yoursite.com or yoursite.com. I personally use www on most sites I own however many people prefer to drop it, it’s really up to you.


Force users to use http://www.yoursite.com


To force users to use the www version of your domain all you have to do is add the following code to your .htaccess file (just replace yoursite.com with your domain name).

# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
Alternatively you can use :

# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Force users to use http://yoursite.com
To force users to use the non www version of your domain all you have to do is add the following code to your .htaccess file (just replace yoursite.com with your domain name).

# Redirect www urls to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC]
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
Alternatively you can use :

# Redirect www urls to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]


htaccess redirect www to non www syntax

htaccess redirect www to non www code on this is provided for your study purpose, it will guide you to know how to use mod_rewite to create .htaccess files on the apache servers. use it to practice and train your self online

All the tutorials on this site are free, the page code is provifed for you to use it to practice, if you want to help to improve and maintain this work, you can donate to us on.



Htacess tutorial guides withexamples and easy steps to set ip up on your server.


Htaccess Generator

Htaccess block all bad robots

prevent hack

redirect www to non www

modifying the environment variable

file access deny control

cache control no cache and cache public

ip blocking

adding new mime types and set timezone

hot to create file

hide .

gzip page compression

force file save

password protect a directory

hotlink protection

custom error page

stop directory listing

block and allow referrer

set cookie domain authentication

prevent directory listing

php 301 redirect

upload_max_filesize limit

301 redirect

changing home directory page

All the tutorials on this site are provided for free. You can copy and print the tutorials and code on this site, but you are not allowed to reproduce this information on another website. All rights reserverd 2012

Copywright © 2013 www.htaccessredirect301.com Site created By prince Ejike Google+

promo