Remove ".html" from URL via .htaccess for a WordPress website

admin

Administrator
Staff member
<h3>Background information:</h3>

I've searched stackoverflow for a specific solution and couldn't find one that fixed my situation. Thanks in advance for any help you can offer. Your knowledge is appreciated.

I've decided to accept a contract to "convert" (in the client's words) a Joomla site into a WordPress site. Everything is going along smoothly, except that the Joomla site links to .html files, both in its navigation and in the content of 100+ posts.

Instead of going through each post one-by-one and updating the links or running a SQL command to remove ".html" from URLs, I've decided to put the pressure on .htaccess, with which I am somewhat comfortable.

<hr>

<h2>What I'm trying to do &darr;</h2>

In WordPress, I have custom permalinks enabled, and it is as follows:
/%category%/%postname%

Here's an example of what one of the <strong>old</strong> URLs in the posts looks like:

Code:
http://the-site.com/category/the-webpage.html

I need the htaccess file to tell the webserver to remove the .html so the user, after visiting "<a href="http://the-site.com/the-webpage.html" rel="nofollow noreferrer">http://the-site.com/the-webpage.html</a>" is instead sent to:

Code:
http://the-site.com/category/the-webpage

I'm setting up the page stubs to follow the file name of the Joomla pages, so <a href="http://the-site.com/category/the-webpage" rel="nofollow noreferrer">http://the-site.com/category/the-webpage</a> will work.

<hr>

<h2>My question:</h2>

Can you help me discover the solution to removing .html from the URL when someone visits the site, even if the HTML file doesn't exist on the server?

<hr>

<em>Here's how the .htaccess file looked before I made changes:</em>

Code:
# BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;
# END WordPress

<strong>Here's the latest .htaccess file as of <em>5:35pm</em> Eastern:</strong>

Code:
# BEGIN WordPress
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]
# END WordPress

<hr>

<h2>The &uarr;latest .htaccess changes work. <a href="https://stackoverflow.com/questions...ccess-for-a-wordpress-website/3128949#3128949">Thanks Tim!</a></h2>