There are tons of posts regarding "remove PHP extensions." I've tried a bunch. Some work... some don't... but none do what I need. [Note: this was marked as a "duplicate" ... yet noone can provide me with a link to a solution here]
The code below allows my users to go to a page, and view it WITHOUT the php extension. However, I need the users to be redirected from the URL with an extension, to the no-extension URL ... Right now, going to "page.php" lets them view the URL as www.website.com/page.php (they need to see www.website.com/page).
Right now:
GO TO: www.website.com/page
--- URL IS: www.website.com/page
GO TO: www.website.com/page.php
--- URL IS: www.website.com/page.php
--- NEEDS TO BE : www.website.com/page
Code is below:
RewriteEngine on
# remove php ext
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# http to https
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# Add www to any URLs that do not have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Someone said this was a duplicate post where the solution was:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
That didn't work. It does exactly what my code does above.
Found the following that worked...
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]