Thursday 9 May 2019

Remove .html extension, redirect HTTP to HTTPS in .htaccess file

In .htaccess file change the following :


#example.com/page will display the contents of example.com/page.html

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.html -f

RewriteRule ^(.+)$ $1.html [L,QSA]



#301 from example.com/page.html to example.com/page

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/

RewriteRule ^(.*)\.html$ /$1 [R=301,L]




For Godaddy add:



 Options -MultiViews



For http to https redirect



RewriteCond %{SERVER_PORT} 80

RewriteCond %{HTTP_HOST} ^(www\.)?citycentreupcc\.ca

RewriteRule ^(.*)$ https://www.citycentreupcc.ca/$1 [R,L]




Full code 

Options -MultiViews

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?citycentreupcc\.ca
RewriteRule ^(.*)$ https://www.citycentreupcc.ca/$1 [R,L]


#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/

RewriteRule ^(.*)\.html$ /$1 [R=301,L]


https://stackoverflow.com/questions/5730092/how-to-remove-html-from-url

No comments:

Post a Comment