Welcome to WebmasterWorld Guest from 54.226.67.166

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

[L,R=301] doesn't redirect right.

     

Jesse_Smith

5:16 pm on Aug 22, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



XBitHack Full
Options +Includes
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^print/([^.]+)/([^.]+)\.shtml$ http-//www.domain.com/print/$1-$2.shtml [L,R=301]
RewriteRule ^([^.]+)/([^.]+)\.shtml$ http-//www.domain.com/games/$1-$2.shtml [L,R=301]

It spits out a firefox error,

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

and ends up redirecting like...

http-//www.domain.com/10/File.shtml
to
http-//www.domain.com/games/games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-10-File.shtml

or

http-//www.domain.com/print/10/File.shtml
to
http-//www.domain.com/games/games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-games-print-10-File.shtml

g1smd

5:45 pm on Aug 22, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Yep. That's exactly how it is coded.

The redirected-to URL rematches the RegEx pattern and is redirected again.

You need to tighten the RegEx pattern so that it does not match URLs that should not be redirected.

Perhaps URLs with a hyphen should not be redirected?

phranque

8:40 pm on Aug 22, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



you probably need a RewriteCond to prevent the last RewriteRule from firing when the requested path already begins with "/games/".

lucy24

11:10 pm on Aug 22, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



More stuff:

Options +Includes
Options +Indexes
Options +FollowSymlinks

These three items can be combined in a single line; that's what the + is for. When you say Options +Indexes do you mean Options -Indexes? I don't see many sites that want to enable auto-indexing by default in all directories.

RewriteRule ^print/([^.]+)/([^.]+)\.shtml$ http-//www.domain.com/print/$1-$2.shtml [L,R=301]
RewriteRule ^([^.]+)/([^.]+)\.shtml$ http-//www.domain.com/games/$1-$2.shtml [L,R=301]

I was going to say http- is a typo for http: and then I realized you did it to prevent auto-linking. That's one reason you should use example.com. It can be example.some-other-tld if you need to name more than one domain.

In patterns like this
([^.]+)/


you almost certainly want
([^./]+)/

instead. Otherwise you'll be capturing requests like
(aaa/bbb/ccc)/(ddd/eee/fff.shmtl)

Even requests for
aaa/bbb/ccc.shtml

will involve backtracking. "Oh, oops, I was supposed to leave room for a / slash, why didn't you say?"

you probably need a RewriteCond to prevent the last RewriteRule from firing when the requested path already begins with "/games/".

Or change the pattern itself to something like
^(dir|otherdir|thirddir)/blahblah
Use this form if you only have a few top-level directories.

Jesse_Smith

6:26 am on Oct 20, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, tightening the RegEx pattern got it working, making it only redirect when the fake directory is a number.

RewriteRule ^print/([0-9]+)/([^.]+)\.shtml$ http://www.example.com/print/$1-$2.shtml [L,R=301]
RewriteRule ^([0-9]+)/([^./]+).shtml$ http://www.example.com/games/$1-$2.shtml [L,R=301]

g1smd

6:55 am on Oct 20, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Don't forget to escape the literal period in the second RegEx pattern in the same way you have in the first.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month