views:

183

answers:

1

Hi, i'm deploying a ror application and now i have to rewrite the url (in apache) to

  • add a prefix www to the url
  • add / to the end of the url

So i took the following approach:

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

The problem is that it is appending two trailing slash to my url So for example a resource /question/ask are becoming:

http://foo.com//question/ask

I tried to add the following Rule before all my Rewrite rules to try to remove the double //:

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

but it didnt work.. any idea to rip off all extras "//" added to the url?

+1  A: 

The $1 will include a / at the beginning. You probably want

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