How can i redirect all posts permalinks to .html ,in WordPress ? now all my posts url are ending in .html ,but before it was without .html
to be more clear ,for example a post url like this www.example.com/posturl to be redirected to www.example.com/posturl.html .it’s simple to redirect them one by one,but i need a rule to redirect all posts .
Thank you
You can edit your .htaccess directly or download an htaccess editor plugin for WordPress. Then write your rule similar to this:
For more detailed instructions
You can add an extension to your Post permalinks in the WordPress Admin by going to
Settings > Permalinks
and creating a Custom Structure with .html at the end.For example:
This will only work with Posts, though. If you want to add .html to Pages’ permalinks, you can try a plugin like Custom Page Extensions or use the .htaccess rule posted by Bitmap.
There’s a risk with the .htaccess approach. He has to write specific rules to target only posts. Not all URLs on the server.
This is another approach. Works within WordPress, is ‘kind-of’ safer but a bit performance taxing as it needs to load the plugins before it kicks in. Theory is simple. Redirect any URL not containing . in the last segment like /uri or /uri/ to /uri.html … ONLY IF WordPress signals a is_404() error.
Place this plugin in the /wp-content/mu-plugins/redirector.php.
I’d rather go for a .htaccess redirect anytime but it depends. If you really messed up your blog by changing permalink structure LIVE (which should never be done when some traffic/rankings are achieved), this is a safer method as it only acts when an is_404() occurs. Fine tune it if you have issues with categories, etc.
Warning: PHP 5.3+ Closure used. Consider reverting to PHP 5.2 syntax and compatibility… an assignment 🙂
You’ve cited your doing this for SEO purposes.
At the moment there is zero evidence, that adding .html to the end of the URL will improve Google SEO, and by your own admission, Google is indexing the non-html ending URLs instead.
What is more, the .html extension implies the content is static and will never change, meaning Google can index it once and never return. Would it not be preferable for Google to come back? Especially considering that the ‘freshness’ of a page now plays a heavy part in how high it’s ranked.