Forum Moderators: phranque

Message Too Old, No Replies

adding a double slash

htaccess or httpd.conf

         

santapaws

10:07 pm on Nov 1, 2011 (gmt 0)

10+ Year Member



not sure whats going on here. If i add the following code to my htaccess it works fine but if i add to an httpd include it adds a double slash after the domain for redirects from non www to www. Any help? :)

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?\ HTTP/
RewriteRule ^index\.html?$ http://www.example.com/ [R=301,L]

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

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

lucy24

12:43 am on Nov 2, 2011 (gmt 0)

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



Most obvious explanation: the httpd include version includes (sorry) a leading slash, giving you a total of two.

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ 


g1 is going to read you the riot act about the (.*) construction. Admittedly it is very hard to come up with alternatives; in fact there's an ongoing thread elsewhere in this Forum where the poster ended up having to make at least two different Rule-and-Condition sets just to cover all possible permutations of the double slash. Which, incidentally, might as well be //+ just to cover all possible malformities. Oh, and your version doesn't cover the possibility of a leading double slash, where the request_uri begins with /. I guess that's where the second Rule comes in.

At an absolute minimum, say (.*?) so the server will stop at the first occurrence of // rather than wait and see if there will be another one.

santapaws

9:12 am on Nov 2, 2011 (gmt 0)

10+ Year Member



tx lucy, can you post a link to the other thread?

g1smd

8:59 pm on Nov 2, 2011 (gmt 0)

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



Doing some other redirect after your non-www to www redirect means that non-www requests pass through an unwanted redirection chain.

The non-www to www redirect must be last on the list of redirects.

lucy24

9:17 pm on Nov 2, 2011 (gmt 0)

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



can you post a link to the other thread?


Hm, yeah, the subject line doesn't exactly hint at the content does it? The thread meanders a bit but you can pick out all the things that didn't work so you don't have to try them.

[webmasterworld.com...]

The examples are nicely annotated with # lines, so that helps. And, er, if there's a conflict between advice from me and advice from g1, then g1 is right unless it's a blatant typo.