Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite produces an extra /

         

okrogius

12:26 am on Sep 26, 2004 (gmt 0)

10+ Year Member



I"m using mod_rewrite to redirect example.com (or others not www.example.com) to www.example.com. Here's the code:

RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.example.com
RewriteRule ^(.*)$ [example.com...] [R=permanent,L]

The issue is that this produces an unexpected slash. Here's a sample request:

[example.com...]

GET /test HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 301 Moved Permanently
Date: Sun, 26 Sep 2004 00:24:11 GMT
Server: Apache
Location: [example.com...]
Content-Length: 236
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
----------------------------------------------------------

As you can see if I request [example.com...] I get redirected to [example.com...] <- which has an extra slash after the domain name.

If anyone has ideas how to fix, I would be most appreciative.

Birdman

12:48 am on Sep 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about adding a slash before your back-reference.

RewriteRule ^/(.*)$ h*tp://www.example.com/$1 [R=permanent,L]

That should solve it.

Birdman

ps: I added the asterisk to avoid another dead link