homepage Welcome to WebmasterWorld Guest from 174.129.103.100
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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




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

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




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

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




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

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

lucy24




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

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




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved