简体   繁体   中英

How to remove dynamic string from url with htaccess

I just finished my Wordpress website migration and I found that all my posts ids Got changed after the migration what is bad for my SEO because I use the IDs on the URLs.

Example of old URL: http://www.example.com/news/category/postname-ID.html

Example of new URL: http://www.example.com/news/category/postname.html

As you can see I'm not using the IDs anymore on the URLs since it's not the same.

So I would like to know how to use htaccess to rewrite URLs from Example 1 to Example 2

NB: The Id is not the same it dynamic.

Thanks

Give the following rules a try:

RewriteEngine On
RewriteRule ^(news/category/.*)\-\d+(\.html) $1$2 [R=301,L,NC]

assuming that the ID s are numeric. This would also fail, if, for eg. your postname is something like: see-this-post-number-13.html or This-is-year-2015.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM