I have in my .htaccess the following code:
RewriteEngine On
RewriteRule ^/?([^/\.]+)/?$ $1.php [L]
RewriteRule ^/?([^/\.]+).php$ $1/ [R,L]
RewriteRule ^/?([^/\.]+)/?$ $1.php [L]
is working fine. What this is doing is taking a url like http://www.example.com/whatever
and making it read the page as http://www.example.com/whatever.php
.
However, what I'd like to be able to do is take a url like http://www.example.com/whatever.php
and automatically send it to http://www.example.com/whatever
, hence the second line of the code. However, this isn't working. What its doing now, is as soon as it comes across a link ending in .php
, the url becomes http://localhost/C:/Sites/page/whatever/
, and pulling a 403: Forbidden
page.
All I want to know is what I can to so that http://www.example.com/whatever.php
will be read as http://www.example.com/whatever
, and that if http://www.example.com/whatever.php
is entered into the URL bar, it will automatically redirect to http://www.example.com/whatever
.
Does that make any sense?
EDIT
Ok, so it appears I wasn't all too clear.. basically, I want /whatever/
to read as whatever.php
while the URL still stays as /whatever/
, right? However, if the URL was /whatever.php
, I want it to actually redirect the users URL to /whatever/
, and then once again read it as whatever.php
. Is this possible?