Forum Moderators: phranque

Message Too Old, No Replies

Remove double slash at the end of the url

Rewrite Rule

         

homeini

10:29 am on Nov 8, 2007 (gmt 0)

10+ Year Member



Hello, because an error, there is people who links me to:
[mydomain.com...]

The good page is not [mydomain.com...] it's [mydomain.com...] , without the double slash at the end, so I want to redirect it.

I do this:
#RewriteRule ^blog/([0-9]{4})/([0-9]{2})/([0-9]{2})//$ ^blog/$1/$2/$3/ [R=301,L]

But it doesn't work, how can I do it?

Thanks

jdMorgan

3:14 pm on Nov 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The proper form for the rule would be:

RewriteRule ^blog/([0-9]{4})/([0-9]{2})/([0-9]{2})//$ [b]http://example.com/b[/b]log/$1/$2/$3/ [R=301,L]

This assumes that you've got other RewriteRules that work. If not, you'll need some 'set-up' directives to enable the rewriting engine before you try to use it.

Jim

homeini

5:40 pm on Nov 8, 2007 (gmt 0)

10+ Year Member



Hi,

I've got others rewriterules in the .htaccess that work, the one's which don't work is this.

I tried to do with you recomendation:
RewriteRule ^blog/([0-9]{4})/([0-9]{2})/([0-9]{2})//$ http://example.com/blog/$1/$2/$3/ [R=301,L]

But it doesn't work.

Any idea?

jdMorgan

6:04 pm on Nov 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apache may have already removed the double slashes (which it ignores internally) from req_rec. So let's look at the client request itself to detect the double-slashes:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blog/[0-9]{4}/[0-9]{2}/[0-9]{2}//\ HTTP/
RewriteRule ^blog/([0-9]{4})/([0-9]{2})/([0-9]{2})/$ http://example.com/blog/$1/$2/$3/ [R=301,L]

Jim

homeini

9:02 am on Nov 9, 2007 (gmt 0)

10+ Year Member



Thanks Jim!

Now it's running ok :)