htaccess的重定向只工作了URL的一部分 [英] .htaccess redirect only working for part of the URL

查看:104
本文介绍了htaccess的重定向只工作了URL的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从旧网站的光泽重新推出网站重定向一串网址。我的.htaccess正在与目录(即example.com/directory被重定向到example.com/newdirectory~~V)的第一级,但我有重定向下面的问题。这里有一个是不工作的例子:

I'm trying to redirect a bunch of URLs from an old site to the shiny relaunched site. My .htaccess is working with the first level of directories (i.e. example.com/directory is redirecting to example.com/newdirectory), but I'm having issues redirecting beneath that. Here's an example of one that's not working:

Redirect 301 /Expertise/QuantitativeResearch/ /services/quantitative-research/

此进到example.com/services/QuantitativeResearch - 这样的专业目录被重定向,但是URL的QuantitativeResearch部分不是

This goes to example.com/services/QuantitativeResearch - so the Expertise directory is being redirected, but the QuantitativeResearch part of the URL isn't.

我试图将其更改为RedirectMatch301,但它并不能帮助。我想知道如果我需要去掉/专业/,并使用一些正则表达式来代替?在/专业/一部分已经被重定向到/服务/由另一行:

I've tried changing it to RedirectMatch301, but it doesn't help. I'm wondering if I need to strip out /Expertise/ and use some Regex instead? The /Expertise/ part is already being redirected to /services/ by another line:

Redirect 301 /Expertise/ /services/

这会不会造成冲突?我知道我可能失去了一些东西很基本的在这里!只是为了澄清,我重定向都来了后RewriteEngine叙述上了。

Could this be causing conflict? I know I'm probably missing something really basic here! Just to clarify, my redirects are all coming after and before RewriteEngine On.

在此先感谢!

推荐答案

您确实需要在这里使用基于正则表达式匹配。尝试 RedirectMatch 来代替:

You do need to use regex based matching here. Try RedirectMatch instead:

RedirectMatch 301 ^/Expertise/QuantitativeResearch/?$ /services/quantitative-research/

RedirectMatch 301 ^/Expertise/(.*)$ /services/$1

这篇关于htaccess的重定向只工作了URL的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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