homepage Welcome to WebmasterWorld Guest from 50.16.112.199
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

    
mod rewrite: url with a dot not redirecting
starchild

5+ Year Member



 
Msg#: 4391552 posted 2:37 am on Nov 28, 2011 (gmt 0)

Hi,

We have a weird case of where our htaccess is not kicking in when it should.

The path example being /shopping/some-path-name-5.5/100/1

The page should be redirecting to /shopping/some-path-name-55/100/1, but it's showing a 404 instead.

We are running cpanel.

Below is an abridged output of our htaccess file (w start off by catching old file paths, and redirecting to the new as we have migrated systems).

Any help is greatly appreciated. Thanks a lot.




RewriteEngine on


RewriteRule .*/(.*)/p/(.*)/$ /products/$1/$2/1 [L,R=301]
RewriteRule .*/(.*)/p-(.*)$ /products/$1/$2/1 [L,R=301]
RewriteRule .*/(.*)/c/(.*)/page/(.*)/$ /shopping/$1/$2/1 [L,R=301]
RewriteRule .*/(.*)/c-(.*)$ /shopping/$1/$2/1 [L,R=301]
RewriteRule .*/(.*)/g-(.*)-page-(.*)$ /shopping/$1/100$2/$3 [L,R=301]
RewriteRule .*/(.*)/g/(.*)/page/(.*)/$ /shopping/$1/100$2/$3 [L,R=301]


RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} !//

RewriteRule (.*)/(.*)/(.*)/(.*) $1.php?id=$3&page=$4&name=$2 [L,QSA]

 

lucy24

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



 
Msg#: 4391552 posted 5:39 am on Nov 28, 2011 (gmt 0)

:: runs around for a few minutes screaming in horror ::

Last week I was faced with the rhetorical query: What's worse than an initial (.*) ? Two initial (.*) sets. Now in one fell swoop we've got FOUR.

:: pause for some more screaming ::

What is the .* meant to cover? If it's a single directory name, you want [^/]+. That's + not * unless your site is weighted down with malformed URLs along the lines of

www.example.com///g//page// (rule 6)
or
www.example.com//g--page- (rule 5)

By the time you've executed those first six rules-- assuming your server is still standing-- what's left for the final Rule and its Conditions?

/shopping/some-path-name-5.5/100/1

... should be redirecting to

/shopping/some-path-name-55/100/1


I'm getting a headache. Which of your rules 4-6 (the three that redirect to /shopping/ and don't exclude literal periods) is supposed to have this result?

RewriteCond %{REQUEST_URI} !//

Seems a bit superfluous, since your first six Rules all allow for // and even ///

:: sob ::

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4391552 posted 8:08 am on Nov 28, 2011 (gmt 0)

There's only three things right with your initial code.
You have correctly listed redirects before rewrites.
You have correctly used the R=301 flag.
Every rule correctly has the L flag.

There are however, multiple serious problems.
First, the redirect target should include the protocol and domain name to avoid duplicate content issues.
Second, please read everything that has been said here over the last decade about not using the (.*) grouping at the beginning or in the middle of a RegEx pattern and about never using more than one (.*) in a pattern.
Thirdly, unless you want your server hacked by opportunists, that $1.php rewrite target needs a prepended leading slash, like /$1.php...

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