Forum Moderators: phranque

Message Too Old, No Replies

Simple Rewrite rule

exampl.com to www.example.com

         

Moff

3:54 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



Wonder if anyone can help me. Currently surfing to mysite.com gives me a 404 message. I thought using the following code would send me to www.mysite.com but it doesn't appear to be working.

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

It doesnt give me any errors at all, just doesnt work.

Romeo

4:05 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



Hi Moff,

Basically, I use the same code, and it should work.
Do you have a
"RewriteEngine on"
in front of your code?

Regards,
R.

One minor point:
in the RewriteCond line you may escape the dot in the domain name, otherwise in your case both "example.com" and "exampleXcom" would match:
^example\.com

Moff

4:14 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



Thanks for the tip Romeo.

There are RewriteRules earlier on the .htaccess that work fine. Im pressuming I dont have to have a rewriteEngine on entry for every set of rules?

One other thing i thought of, the domain has a couple of hyphens in it, do these need to be escaped aswell?

Moff

jbgilbert

4:23 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



Moff,
If it's not working yet, try this in your .htaccess file... works well for me. assume domain is domain.com

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.domain\.com
rewriterule (.*) [domain.com...] [R=permanent,L]

Romeo

4:34 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



> Im pressuming I dont have to have a rewriteEngine on entry for every set of rules?

Yes, you don't need multiple ones.

> the domain has a couple of hyphens in it, do these need to be escaped aswell?
... not that I know ...

Do you have more rewite rules above your code terminated with [L], which already have been applied, so this new rule would not be reached at all?

Sorry, no more ideas here.

Regards,
R.

jdMorgan

4:43 pm on Feb 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have a DNS A record in your zone file to map "example.com" to your server's IP address? You should have at least two A records, one for "www.example.com.", and one for "example.com." -- Note the periods on the end.

Jim

Moff

4:43 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



Thanks for you help guys,

It looks like that was the problem jdMorgan, cant help feeling slightly stupid :~)

Thanks again.

Moff