Forum Moderators: phranque

Message Too Old, No Replies

redirect example.com/page.htm to www.example.com/page.htm?

         

jasonlambert

4:00 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



Problem:
Google has decided to index 8k of my pages without the "www." prefix.

Question:
Can someone provide an example .htaccess rule that will 302 redirect example.com/page.htm to www.example.com/page.htm?

Thanks

johnt

5:13 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



I think that you'd be better off using a 301 ( permanent ) redirect rather than 302 ( temporary ). This will tell Google to consolidate the links and the PR that the two versions of the page have into just the www. version.
If you want to use 302 just replace the 'permanent' below with 'temporary'.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) [example.com$1...] [R=permanent]

should do the trick.

Cheers

John

inbound

1:53 am on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this didn't work for me, does it work for others?

jdMorgan

2:35 am on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please define "didn't work". Did your server produce an error, did nothing happen at all, or what did you see? There are many "default" server configurations, and while the code posted above is correct, it may not work for you depending on how your server is configured.

If you have any data from your server error log, pleas include it.

Jim

inbound

3:16 am on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry about the very vague 'didnt work' I will expand on this, and I think it is the setup of my server that is to blame so my apologies for the poor post.

The simple redirect for domain.com to www.domain.com works perfectly.

The problem on my server is that it appends the directory structure on to the end of the domain so domain.com/page.htm becomes www.domain.com/directorystructure/page.htm

This would not be a problem if the document was in the root, I assume. However I have around a dozen active sites on the server and each sits in a directory just off root.

I would imagine that stripping the (known) directory/ from the $1 bit would work as all files are in the same directory.

I have posted this same query in another post (before checking this) so sorry for the duplication.