Welcome to WebmasterWorld Guest from 54.166.191.159

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite: url with a dot not redirecting

     
2:37 am on Nov 28, 2011 (gmt 0)

10+ Year Member



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]
5:39 am on Nov 28, 2011 (gmt 0)

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



:: 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 ::
8:08 am on Nov 28, 2011 (gmt 0)

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



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...
 

Featured Threads

Hot Threads This Week

Hot Threads This Month