0

I have PHP project on my localhost, which is running a XAMPP stack.

I want to remove the .php extension from all user-facing URLs.

I've tried using Apache's mod_rewrite in an .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^locations(/.*)?$ poet.php [L,NC]
</IfModule>

But it is "not working".

Jameson
  • 6,400
  • 6
  • 32
  • 53
  • 1
    Possible duplicate of [Remove .php extension with .htaccess](http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess) – Abhishek Gurjar Mar 07 '17 at 06:18
  • @Abhishek I have seen this post when i google but this step is not working so finally i decided to ask question –  Mar 07 '17 at 06:20
  • RewriteEngine on RewriteRule ^(.+)\.php$ /$1 [R,L] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ /$1.php [NC,END] –  Mar 07 '17 at 06:23
  • when i use this i found 404 page –  Mar 07 '17 at 06:23
  • @VivekMishra If you came across relevant questions or other material that did not help it is a good idea to state that in your question. This way people will know what you tried and someone may spot the difference. – MB-F Mar 07 '17 at 07:11

4 Answers4

0

Try this code solution your problems

     <IfModule mod_rewrite.c>
           RewriteEngine On
           RewriteCond %{REQUEST_FILENAME}.php -f
           RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
     </IfModule>
Khetesh kumawat
  • 681
  • 7
  • 15
0
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L]
Riddhi Rathod
  • 410
  • 2
  • 9
0

Try below rule in your project directory,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
0

put this code in your .htaccess file

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

Note: don't forgot to change RewriteBase path if your project folder is not on root.

  • don't forgot to change RewriteBase path if your project folder is not on root. i can't understand this. its my first htaccess –  Mar 07 '17 at 06:44
  • it means if your project is on root of htdocs folder then use the above code as it is, but if your project is not on root of htdocs then please specify the path upto your project folder .... e.g. suppose your project is inside htdocs/projects/demoproject1 ...... then RewriteBase path will be like this RewriteBase /projects/demoproject1/ – Full Stack Tutorials Mar 07 '17 at 06:51