سؤال

I'd plastered all over the Internet that this code in your .htaccess file will remove the file ending:

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

However, although enables the URL without file ending, it does not disable the URL with file ending.

Essentially, what I'd like to force any attempt for an request with file ending (domain.com/sample.php) to end up without file ending (domain.com/sample)

I'm sure someone will have covered this somewhere, but I cannot find anything.

Many thanks.

هل كانت مفيدة؟

المحلول

Add this extra rule before your existing rule:

RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top