Hi Everyone!
I working on a website where the basic URL structure is example.com
and then I used a code in .htaccess file to redirect them all to http://www.example.com
. Everything is fine and later I planned to remove the file extension from the URL i.e., www.example.com/page1.php
, www.example.com/page2.html
.
So, I have done a lot of research and finally came to a code where it resolved my issue but the thing is I can still access both the URL structures such as
www.example.com/page1.php
& www.example.com/page1
So, Can you help me out with this
I just need one URL Structure for my website.
i.e., www.example.com/page1
Code in .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
Thank you in advance