简体   繁体   English

如何使用apache url重写仅删除部分URl字符串?

[英]How to remove only part of URl string using apache url rewrite?

I have thousands of URLs that look like this: 我有成千上万个如下网址:

http://www.domain.com/here-is-a-product-ab00007a1.html

The number at the end of the URL (before the .html) is the SKU. URL末尾(.html之前)的数字是SKU。 The site has recently been relaunched and these numbers no longer exist in the URLs. 该站点最近已重新启动,并且这些数字不再存在于URL中。

I would like to redirect all URLs like this to their new version which does not include the SKU, example: 我想将所有这样的URL重定向到不包含SKU的新版本,例如:

http://www.domain.com/here-is-a-product.html

Any help would be greatly appreciated! 任何帮助将不胜感激! Thank you. 谢谢。

===== EDIT ===== =====编辑=====

The actual sku format is like so: 实际的sku格式如下:

aa00000a00

There are always 2 letters , followed by 5 numbers , followed by 1 letter , followed by 2 numbers . 总有2个字母 ,后跟5个数字 ,然后是1个字母 ,后跟2个数字

The sku is always 10 characters long . sku 总是10个字符长

Try putting this in the htaccess file in your document root: 尝试将其放在文档根目录的htaccess文件中:

RewriteEngine On
RewriteRule ^(.*)-[a-z]{2}[0-9]{5}[a-z][0-9]{2}\.html$ /$1.html [L,NC]

You can also put that in your vhost/server config if you'd rather do that, just remove the leading slash from the rule's target so that it's simply: $1.html 如果愿意,还可以将其放在您的vhost / server配置中,只需从规则目标中删除前导斜杠即可,即: $1.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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