Forum Moderators: phranque

Message Too Old, No Replies

problem with www redirect after Apache upgrade

rewrite to redirect non-www requests to www requests no longer works

         

deesto

7:23 pm on Jun 19, 2012 (gmt 0)

10+ Year Member



I had rewrite conditions and a rule to send requests not including 'www' in the domain to the appropriate domain URL, i.e., http://example.com --> http://www.example.com

After upgrading Apache from 2.2.3 to 2.2.15, this rewrite no longer works and requests fall through to a default catch-all rule:

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


Did something change in the way Apache handles rewrite conditions, or was this rule faulty?

lucy24

11:42 pm on Jun 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your rule as written cannot possibly have worked in Apache 2.2.anything, because the Rule itself sees only the body of the URL, not the domain. (Also not the query, if any.)

The Conditions as written also make no sense. If the Host begins with "example.com" then by definition it cannot be "www.example.com" or, for that matter, www.anything.

Are you sure you weren't on Apache 1.something? Only yesterday there was a question from someone with an all too well-known host who had only just upgraded from 1.3 to 2.2.

g1smd

11:48 pm on Jun 19, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the sixth time in two days...

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

deesto

3:10 pm on Jun 20, 2012 (gmt 0)

10+ Year Member



While I appreciate the replies, and apologize for asking a question that seems to have been answered before (multiple times, apparently), and understand after reviewing these rules that they perhaps should never have worked in the first place, I can assure you that they did indeed work before (in v.2.2.3), and that after fixing a DNS issue, they seem to be working again. Of course, that doesn't mean I won't fix them by replacing them with something that seems a bit more sensible and that will actually work as expected. Thanks again for your replies.

g1smd

6:28 pm on Jun 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is it possible that requests on the old site were being redirected because of an unseen rule in the main server configuration file, i.e. in httpd.conf or elsewhere?