Welcome to the forum. If this is your first time you can browse around and see what you like. You will need to be registered in order to post!

Join our community and talk about tech, gaming, get support for computer problems and even sale your own product.
Considering supporting us by subscribing.

Force .html redirection on Wordpress

Post Reply
User avatar
Site Admin
Site Admin
Posts: 47
Joined: Sat Jul 01, 2017 9:35 pm

Force .html redirection on Wordpress

Post by kachan64 » Mon Apr 15, 2019 12:48 pm

If you are converting website from static html pages to Wordpress pages or trying to fix Google search result that still showing html pages from your own site, you can use a simple rewrite rule in your .htaccess.

First code I tried was:

Code: Select all

redirectMatch 301 ^(.*)\.html$ $1
But the problem is that any url on yourwebsite.com will result in yourwebsite.com/index because of the RewriteRule . /index.php [L].

The second code I found on this Stack Overflow post works perfectly.

Code: Select all

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
You will need to replace the entire code inside <IfModule mod_rewrite.c>.

In my case any URL that ends with html on Google search result will be redirected to it's relevant pages.
i.e: yourwebsite.com/some-page.html will become yourwebsite.com/some-page.
PC: Custom Built Gaming PC
Monitor: Samsung S24D390H, Asus VE248H

Post Reply

Return to “WordPress”

Who is online

Users browsing this forum: No registered users and 0 guests

Topic Subscribers

1 user subscribed to this topic: kachan64