Welcome to WebmasterWorld Guest from 54.147.44.93

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect not working correctly when trailing slash is left off url

     

nigelt74

2:24 am on Aug 1, 2010 (gmt 0)

10+ Year Member



Hi

In the course of investigating a seperate problem i found my redirect isn't working correctly if the user doesn't add a trailing slash to the url they are entering

basically i am redirecting /phpBB3 to /forum

eg
example.com/phpBB3/ redirects BUT
example.com/phpBB3 doesn't


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



My rule is shown above, and i can't seem to fis it without breaking the functionality of the above rule, Its a really minor thing (according to my stats there's only been 20 404s because of it) its just bugging me as It should work

jdMorgan

3:02 am on Aug 2, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Make the slash optional, as well as anything that might follow:

RewriteRule ^phpBB3(/(.*))?$ http://example.com/forum/$2 [L,R=301]

Jim

nigelt74

1:38 am on Aug 3, 2010 (gmt 0)

10+ Year Member



Thanks for that Jim

just one question why are you using $2 rather than $1

jdMorgan

1:51 pm on Aug 3, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



To avoid duplicating the slash if it is present in the requested URL-path. Using $1, if example.com/phpBB3/something was requested, you would end up with example.com/forum//something.

An alternative would be to use two rules, one for "example.com/phpBB3" requests, and another for "example.com/phpBB3/<anything or nothing>" requests, but that would be rather a waste of bytes and CPU time.

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month