Forum Moderators: phranque

Message Too Old, No Replies

Yet another non-www to www question

Modifying an existing rewrite

         

akmac

6:03 pm on Jun 7, 2006 (gmt 0)

10+ Year Member



I've currently got this in my .htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}

ErrorDocument 403 /errorpages/403.html
ErrorDocument 401 /errorpages/401.html
ErrorDocument 500 /errorpages/500.html
ErrorDocument 400 /errorpages/400.html
ErrorDocument 404 site_map.php
RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^(.*) [mysite.com...] [L,R=301]

But I want to change it so that it will redirect non-www urls to www urls. I've mucked about with it a few times, and managed to cause my site to *Poof* disappear. After each of these experiences, I vow to leave it alone-but a few months later I get reckless again. like now. Any help?

jdMorgan

12:13 am on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It basically looks OK. How, specifically, does your site go poof when this is installed?

Jim

akmac

4:58 pm on Jun 8, 2006 (gmt 0)

10+ Year Member



Sorry-I wasn't specific enough.

This code works fine-for rewriting my urls AFTER the domain. But I want the added functionality of redirecting non-www requests to www to avoid the canonical issues I've read so much about.

I've tried to modify the code myself to accomplish this using various snippets, but my experiments alwayr resulted in the aforementioned "Poof".

jdMorgan

9:26 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like to know what you mean by "poof" -- What does that mean? If this is an auto repair garage, you'd just dropped off a car and left a note on the windscreen that says, "Won't run" with no other information. Shall I start by putting in a new engine, or maybe it's just out of gas?...

Again, what specifically happens when you run this code? What do you see in the browser, and what do you see in your server access log and your server error log?

I assume you are aware that the code you posted contains the domain redirect code -- The wording of your first post says, "here's what I've got, but when I *add* a domain redirect..." But the domain redirect is already in there, and should already be working for all requests, actually.

Jim

akmac

11:06 pm on Jun 8, 2006 (gmt 0)

10+ Year Member



I was not aware that there was a domain redirect included in the original posted code-sorry! I assumed there was not, because if I type mydomain.com into a browser, it loads-without redirecting to www.mydomain.com.

The "poof" I was referring to was my previous attempts to merge this-

RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ [yourdomain.com...] [L,R=301]

-into what I originally posted-which is the code that is currently in my htaccess file at the url I pmed you. Thanks for your time on this, and apologies for my ignorance.

jdMorgan

11:32 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sorry. Without knowing the symptoms and exactly what you mean by 'poof,' I cannot assist. Having asked two specific questions and received no answer, it's seemingly pointless.

Jim
(Who wonders if he's taking the mickey on this one...)

akmac

8:26 pm on Jun 9, 2006 (gmt 0)

10+ Year Member



These lines worked:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule (.*) [mysite.com...] [R=301,L]

Apologies for the bother.