Redirect all posts permalinks from ".html" to ""

admin2025-01-08  4

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
Share Improve this question edited Oct 8, 2016 at 15:49 Ethan Rævan 4,0295 gold badges27 silver badges55 bronze badges asked Oct 8, 2016 at 15:22 anouarpacanouarpac 112 bronze badges 1
  • Has this question been resolved? – Ethan Rævan Commented Oct 13, 2016 at 14:00
Add a comment  | 

1 Answer 1

Reset to default 0

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
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736266288a1109.html

最新回复(0)