Aadi
Aadi

Reputation: 7109

How to Redirect http://example.com to http://www.example.com

How to Redirect http://example.com to http://www.example.com using htaccess

Upvotes: 0

Views: 655

Answers (2)

Daniel K
Daniel K

Reputation: 7083

use a .htaccess file with following content:

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

In case of IIS make sure, that the host listens to all urls you want to use for your block (including www.example.com and example.com)

Then use the rewrite module of the IIS:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module

You can easily import rules from Apache mod_rewrite into ISS:
http://learn.iis.net/page.aspx/470/importing-apache-modrewrite-rules

Upvotes: 4

Sven
Sven

Reputation: 952

By having a correct configured DNS. Make sure you have following line:

@      IN A   your.server.ip.address

Which says anyone requesting yourdomain.bla will be sent to the server with the given IP. In your case, the IP-address would be the same as the CNAME configuration for "www".

Though, if you use a web hotel service they are too often not letting the customer make a default config. It might be then that you're not able to make the config needed.

Upvotes: 0

Related Questions