3

Well, I know that it should be done by .htaccess my .htaccess is in the root of my site and here it's content

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

Also mod rewrite is enabled at my server. I have a form with an action on ./getReadings.php in it. But when I change it to ./getReadings it says that tehre isn't such file on server. What's my mistake?

Sergey Scopin
  • 2,217
  • 9
  • 39
  • 67

3 Answers3

4

Try adding Options -MultiViews before RewriteEngine directive

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L,QSA]

Note: MultiViews is about Apache content negociation (which is the problem here since filename will automatically be translated as filename.php existing file). That's why you have to disable it.


EDIT: right now, you can access same content by 2 different urls (with or without php extension). To avoid duplicate content (which is bad for search engines) you can redirect extensions to extensionless equivalent with this code

Options -MultiViews
RewriteEngine On

RewriteCond %{THE_REQUEST} \s/(.+?)\.php [NC]
RewriteRule . /%1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L,QSA]
Justin Iurman
  • 18,954
  • 3
  • 35
  • 54
1
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Mad Angle
  • 2,347
  • 1
  • 15
  • 33
0
    RewriteEngine on 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php
Peter Manoukian
  • 158
  • 1
  • 13
  • 1
    Please avoid posting code only. You should also add an explanation of what the code is doing. – arco444 Sep 29 '14 at 10:23