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

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


This will work to force an external redirection to your new URLs, but this may not be ideal for your situation. I'm still trying to think if there's a way to keep the redirection internal and update the variable that WordPress uses to determine which page to serve up, but so far I haven't thought of anything that would work.

Entire .htaccess:

RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_URI} \.html$RewriteRule ^(.*)\.html$ $1 [R=301,L]RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]


You want to use a URL rewrite

RewriteEngine OnRewriteRule ^(.*)\.html$ $1


This should do it. It will rewrite a request to site.com/category/whatever.html to site.com/category/whatever. it shouldn't be dependent upon the requested file existing.

    <Directory /var/www/category>        RewriteEngine on        RewriteRule (.*)\.html$ /category/$1    </Directory>

This is the format for apache2.conf or virtual host files. Not sure if you use the command in .htaccess. It's best to take care of it in the server conf, if you can, as that is only parsed once, on server startup, and htaccess is parsed on each request.