[英]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. 我刚刚完成了Wordpress网站迁移,发现迁移后所有帖子ID都发生了变化,这对我的SEO不利,因为我在URL上使用了ID。
Example of old URL: http://www.example.com/news/category/postname-ID.html 旧网址示例: http : //www.example.com/news/category/postname-ID.html
Example of new URL: http://www.example.com/news/category/postname.html 新网址示例: 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. 如您所见,由于不一样,我不再在URL上使用ID。
So I would like to know how to use htaccess to rewrite URLs from Example 1 to Example 2 因此,我想知道如何使用htaccess将URL从示例1重写为示例2
NB: The Id is not the same it dynamic. 注意:Id与其动态不同。
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. 假设
ID
是数字。 This would also fail, if, for eg. 如果,例如,这也将失败。 your postname is something like:
see-this-post-number-13.html
or This-is-year-2015.html
您
see-this-post-number-13.html
类似于: see-this-post-number-13.html
或This-is-year-2015.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.