1

I never really have used mod re write and I am trying to understand the best way to implement it. removing the .php extension. i found this code

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

problem is that if the link is to domain.com/index.php it wont re write it domain.com/index

Also if i do the link domain.com/index the person can still add the .php and it still works fine.

I would like to know the proper way.. do i have to hard code the urls in the html or is there something that can do it automatically?

I dont want them to be able to add the .php to the end

Amoro
  • 65
  • 6
  • Possible duplicate of [How can I use .htaccess to hide .php URL extensions?](http://stackoverflow.com/questions/10028025/how-can-i-use-htaccess-to-hide-php-url-extensions) – ldg Jul 01 '16 at 04:38
  • You need to allow for both conditions, see the duplicate answer. If the point of hiding the ".php" extension is to obfuscate php, you might consider a 404 instead or route all extensions to the base route. If it's to prettify the urls, then [this](http://stackoverflow.com/questions/10028025/how-can-i-use-htaccess-to-hide-php-url-extensions) should work. – ldg Jul 01 '16 at 04:54

1 Answers1

0

You need an additional rule to remove .php . The rule you are using just allows you to access php files without their extension but doesn't remove the extension. To remove the .php you can use :

RewriteEngine on
#1) redirect "/file.php" to "/file"
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [L,R,NE]
#2) internally map "/file" back to "/file.php"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • starkeen how could i add this to the mix http://localhost/site/profile/member.php?user=1308 to http://localhost/site/profile/1308 – Amoro Jul 01 '16 at 06:42