You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Rob Gabaree <li...@rawb.net> on 2006/08/07 16:30:03 UTC

[users@httpd] mod_rewrite rewriting URLs with an additional "/" at the end? (www->non www)

Hi,

I'm trying to use mod_rewrite to redirect any "www.domain.com" -> 
"domain.com".  I've set up the following rule:

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

This works fine, but whenever I try to go to "www.domain.com", I am 
taken to: "domain.com//" with _two_ slashes instead of one.  Does anyone 
have a clue why this is happening?

It also happens when I append anything after it, ie:

www.domain.com/hello.jpg -> domain.com//hello.jpg
www.domain.com/myfolder/ -> domain.com//myfolder

Thanks.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite rewriting URLs with an additional "/" at the end? (www->non www)

Posted by "Neil A. Hillard" <ne...@agustawestland.com>.
Hi,

Rob Gabaree wrote:
> I'm trying to use mod_rewrite to redirect any "www.domain.com" ->
> "domain.com".  I've set up the following rule:
> 
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
> RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
> 
> This works fine, but whenever I try to go to "www.domain.com", I am
> taken to: "domain.com//" with _two_ slashes instead of one.  Does anyone
> have a clue why this is happening?
> 
> It also happens when I append anything after it, ie:
> 
> www.domain.com/hello.jpg -> domain.com//hello.jpg
> www.domain.com/myfolder/ -> domain.com//myfolder

Yes, the .* catches the leading '/'.  Use either:

RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]

or

RewriteRule ^/(.*)$ http://domain.com/$1 [R=301,L]


HTH,


				Neil.

-- 
Neil Hillard                    neil.hillard@agustawestland.com
AgustaWestland                  http://www.whl.co.uk/

Disclaimer: This message does not necessarily reflect the
            views of Westland Helicopters Ltd.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite rewriting URLs with an additional "/" at the end? (www->non www)

Posted by Evan Platt <ev...@espphotography.com>.
At 07:30 AM 8/7/2006, you wrote:
>Hi,
>
>I'm trying to use mod_rewrite to redirect any "www.domain.com" -> 
>"domain.com".  I've set up the following rule:

Do you mean if I go to www.domain.com/blahlbnlasd.html , it redirects 
to just domain.com , or if I go to www.domain.com it goes to 
domain.com ? If the former, an easier method might be to set a error 
page as http://domain.com . If the latter, you might be able to 
accomplish that via DNS, but I'm a novice, so.. :)


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org