Forum Moderators: phranque

Message Too Old, No Replies

using .htaccess to rewrite url? or httpd.conf vhosts?

htaccess mod_rewrite

         

markh2

6:29 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Here is my issue:

I want my example.com to forward to www.example.com

I have tried everything from just using redirect in htaccess but it throws it into a loop.

How can I make it so that everytime someone visits http://example.com(without www) they get forward to http://www.example.com(with www). Thanks for your help its greatly appreciated, and if you have the answer could you include the code, I am having a rough time with this.

Mark

[edited by: engine at 8:20 pm (utc) on Feb. 6, 2004]
[edit reason] examplified and de-linked [/edit]

jatar_k

8:18 pm on Feb 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld markh2,

we made a virtual host for [example.com...] and then redirect in httpd.conf

Redirect Permanent / "http://www.example.com"

may not be the best way but it works perfectly

<added>some thoughts here too
Indexed with and without "www." prefix [webmasterworld.com]

jdMorgan

5:03 am on Feb 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



markh2,

If both domains use the same server space, you may need to use mod_rewrite to prevent a redirection loop. For httpd.conf:


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

or for .htaccess:

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

Jim