Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Invoking .php script rather than following redirect

.php apache redirect rewriterule

9:01 am on Sep 16, 2010 (gmt 0)

New User

5+ Year Member

joined:Oct 12, 2009
posts: 9
votes: 0

Hi All,

Having a problem at the moment running a website locally (under Ubuntu Linux 10.04) which is working fine on the live website (under CentOS).

The following redirect in the .htaccess file should redirect a call to 'www.domain.com/products/promotional_desk_plants.html' to the searchresults.php script, passing it the product as a query string:

RewriteRule ^products/promotional_(.*)\.html$ /searchresults.php?ln=$1 [NC,L]

This works fine on the live website, but when running locally on the Ubuntu box it is invoking the products.php script, which exists in the root directory, rather than following the redirect.

As a test I created a script in root directory called ‘andy.php’ and if I type in ‘http://domain.local/andy/xxrubbishxx’ it calls the ‘andy.php’ script, rather than giving a ‘page not found’.

Any help on this greatly appreciated!

11:44 pm on Sept 17, 2010 (gmt 0)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:June 12, 2005
votes: 13

Hi Andy,

Do you have mod_speling activated in your local apache install?

Also, put a

AcceptPathInfo off

at the beginning of your .htaccess file (in the local Ubuntu box).

If it's not done by some other rules you have in your .htaccess as well I suspect a AcceptPathInfo on handed over to mod_speling, the last one searching for for similar named files (products->products.php) and handing it over.
4:53 pm on Sept 18, 2010 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
votes: 0

That code is an internal URL-path-to-filepath rewrite, not an external client URL-to-URL redirect. Don't confuse the two, as it makes understanding and using mod_rewrite much more difficult.

As well as mod_speling, you could be getting interference from mod_negotiation. If not required by your site, disable content negotiation by adding "-MultiViews" to the Options directive likely already at the top of your .htaccess file. For example:
Options +FollowSymLinks -Indexes -MultiViews 

is a "typical" setting when using mod_rewrite.

7:39 pm on Sept 21, 2010 (gmt 0)

New User

5+ Year Member

joined:Oct 12, 2009
posts: 9
votes: 0

Spiekerooger & Jim,

Many thanks for your help on this. I'll try these options out and let you know.