How can I redirect all posts permalinks from .html
to /
in WordPress?
To be more clear, for example, a post URL like this:
/%category%/%postname%.html
To be redirected to:
/%postname%/.html
It's simple to redirect them one by one, but I need a rule to redirect all posts. My current .htaccess
setup is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
How can I redirect all posts permalinks from .html
to /
in WordPress?
To be more clear, for example, a post URL like this:
http://example.com/%category%/%postname%.html
To be redirected to:
http://example.com/news/%postname%/.html
It's simple to redirect them one by one, but I need a rule to redirect all posts. My current .htaccess
setup is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Add this to your .htaccess
below the # END WordPress
line:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*)/(.*).html$ news/$2/.html [L,R=301]
</IfModule>
This will redirect domains such as:
http://example.com/category/post-name.html
To the following:
http://example.com/news/post-name/.html