logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: RewriteRule - Remove trailing slash
Author
flatcircle



Joined: 27 Jun 2006
Posts: 79

PostPosted: Mon 28 Apr '08 16:11    Post subject: RewriteRule - Remove trailing slash Reply with quote

Hello,

I want to use a Redirect to a webpage in my config.
Because I want to to redirect to a page (and not a directory), I use no trailing slash.

However, there's a possibility that a user still adds a trailing slash.
Which is the (simplest) RewriteRule-syntax to remove this trailing slash?

For example:

http://www.test.com/subdir/ to http://www.test.com/subdir

Somebody can help me out?

Regards.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Mon 28 Apr '08 20:53    Post subject: Reply with quote

#remove trailing slashes
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
Back to top
flatcircle



Joined: 27 Jun 2006
Posts: 79

PostPosted: Mon 28 Apr '08 23:14    Post subject: Reply with quote

Thanks for your answer!

I tested some things out but can't achieve what I want.

I'd like to Redirect a subdir to a specific page for example:

http://www.domain.com/someitem
directs to
http://www.domain.com/dir/subdir/page.htm

The above is working. However when a visitor enters
http://www.domain.com/someitem/ (with slash)
redirects to
http://www.domain.com/dir/subdir/page.htm/
and no content is being shown.

Can I remove the trailing slash by using a RewriteRule to redirect correctly? I'm a bit lost.

Regards.
Back to top


Reply to topic   Topic: RewriteRule - Remove trailing slash View previous topic :: View next topic
Post new topic   Forum Index -> Apache