Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule: where's the '.php' bit come from?

         

jboy

3:16 pm on Dec 5, 2010 (gmt 0)

10+ Year Member



Hello, dead simple question I'm sure, just trying to understand what's going on.

I'm using an Apache 2 server, I have this in my .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.) [NC]
RewriteRule ^http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This request in a browser:
http-//mydomain.com/thepage
is redirected to:
http-//www.mydomain.com/thepage.php

(I've used a - instead of a : above just to stop them appearing as actual urls)

What I just have to find out is, where is the '.php' part coming from? I do not understand that at all and it's counter to how I thought it worked. Yes the thepage's actual file name on the server is thepage.php but surely the text which the above Rewrite cond and rule is working on is the request URL?; obviously not, because the request URL does not contain '.php'.

Thanks.

g1smd

5:59 pm on Dec 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's no way the posted code could ever work.

The RewriteRule has a pattern which can never match any request arriving at your server, and it specifies no target.

In general, when server internal filepaths, filenames, and extensions are exposed as URLs back out on to the web, it is because there is an external redirect happening after an internal rewrite has occurred.

That's down to getting the rules in the wrong order or having conflicting rules from different Apache modules within the same .htaccess file.

Never mix Redirect/RedirectMatch and RewriteRule in the same site. Use RewriteRule for all of the rules.

jboy

7:58 pm on Dec 5, 2010 (gmt 0)

10+ Year Member



Right, so the code I posted was making no difference. I see. Thanks for those tips. Very useful. I'm trying and am stuck on a different tact now, going to post a new question on it. Thanks.

g1smd

8:31 pm on Dec 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What other Redirect or Rewrite code is present in your server configuration?