htaccess将url中的段塞重写 [英] htaccess rewrite slug in a url

查看:45
本文介绍了htaccess将url中的段塞重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并搜索了有关重写规则的帮助,但似乎没有什么与我要尝试的工作特别匹配,希望有人可以提供帮助?

I've searched and searched for help on a rewrite rule but nothing seems to match specifically what I'm trying to do, hopefully someone can help?

我正在尝试替换网址中的某个段,该段之前和之后可能会有其他各种段.

I'm trying to replace a slug in a url that could have various other possible slugs before and after it.

例如

http://www.example.com/slug/old_slug

http://www.example.com/slug/new_slug

/slug/old_slug/slug

/slug/new_slug/slug

/slug/old_slug/slug/slug

/slug/new_slug/slug/slug

或最后:

/slug/old_slug/slug?param=1&param=2

/slug/new_slug/slug?param=1&param=2

如果这听起来令人困惑,则它们是类别中带有各种可能的url参数的产品,而我必须重命名产品,这意味着我想重写SEO和入站链接的旧url.

If that sounds confusing these are products in categories with various possible url parameters after them and I'm having to rename a product that means I want to rewrite the old urls for SEO and inbound links.

推荐答案

您可以在DOCUMENT_ROOT/.htaccess文件中使用以下代码:

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/old_slug(/.*)?$ /$1/new_slug$2 [L,NE,R=302]

这篇关于htaccess将url中的段塞重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆