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?
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]
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With