Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect traffic hitting .html links to TLD homepage

I'm helping a client migrate an old site which used .html extension at the end of the web address to a properly named URL structure. I want to do a redirect for all URLs that end in .html to the homepage.

I tried this but it didn't work:

RewriteRule ^(.*)\.html$ $1http://domain.org [NC]
like image 767
spike5792 Avatar asked Dec 12 '25 21:12

spike5792


2 Answers

Something like this should fit you needs:

RewriteEngine On 
RewriteBase /
RewriteRule (.*)\.html$ / [QSA,R=301,NC,L]
like image 79
Olivier Pons Avatar answered Dec 14 '25 14:12

Olivier Pons


You can use sometihing like this:

  RewriteEngine On 
  RewriteBase /
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteRule ([^/]+)\.html$ index.php?page=$1 [L,NC]

or for permanent redirect

  RewriteEngine On 
  RewriteBase /
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteRule (.*)\.html$ / [R=301,NC,L]
like image 26
Book Of Zeus Avatar answered Dec 14 '25 14:12

Book Of Zeus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!