简体   繁体   English

Apache htaccess 301重定向到新文件名模式?

[英]Apache htaccess 301 Redirect to New Filename Pattern?

I have come up with a snippet of code that might convert an existing filename pattern to a new one: 我想出了一小段代码,可能会将现有的文件名模式转换为新的文件名模式:

RewriteEngine On
RewriteRule (.*)-pi-(.*)\.html$ $1-p-$2 [NE,R]

Before I go messing around on the server, would offer some advice or a better solution? 在弄乱服务器之前,会提供一些建议还是更好的解决方案?

I am hoping to redirect files looking for url containing "-pi-" to "-p-". 我希望将查找包含“ -pi-”的URL的文件重定向到“ -p-”。

From - http: //www.p.com/great-product-pi-37.html To - http: //www.p.com/great-product-p-37.html -http://www.p.com/great-product-pi-37.html -http://www.p.com/great-product-p-37.html

The product name (great-product) and product id (37) change for every product, but the format remains the same. 每个产品的产品名称 (大产品)和产品ID (37)都会更改,但是格式保持不变。

The -pi- reference used to be a pop-up window to a generated image. -pi-引用曾经是生成图像的弹出窗口。 The image is now displayed on the same -p- screen, but search engines keep indexing and searching for the old -pi- image windows. 现在,图像显示在相同的-p-屏幕上,但是搜索引擎会继续建立索引并搜索旧的-pi-图像窗口。

Thanks, in advance. 提前致谢。

That should work with small tweaks, but you need to use a 301 redirect also. 这应该可以进行一些小的调整,但是您还需要使用301重定向。 If you just use [R] without specifying 301 it defaults to 302 . 如果仅使用[R]而不指定301则默认为302 You don't want temporary. 你不要临时的 You want permanent. 你想要永久的。 I would put this above the other rewrites you might have. 我将此放在您可能拥有的其他重写之上。

RewriteEngine On
RewriteRule ^(.+)-pi-(.+)\.html$ /$1-p-$2.html [R=301,L]

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

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