简体   繁体   English

.htaccess重定向仅适用于部分URL

[英].htaccess redirect only working for part of the URL

I'm trying to redirect a bunch of URLs from an old site to the shiny relaunched site. 我正在尝试将一堆URL从旧站点重定向到闪亮的重新启动的站点。 My .htaccess is working with the first level of directories (ie example.com/directory is redirecting to example.com/newdirectory), but I'm having issues redirecting beneath that. 我的.htaccess使用的是第一级目录(即example.com/directory重定向到example.com/newdirectory),但是在该目录下重定向时遇到了问题。 Here's an example of one that's not working: 这是一个不起作用的示例:

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

This goes to example.com/services/QuantitativeResearch - so the Expertise directory is being redirected, but the QuantitativeResearch part of the URL isn't. 这将转到example.com/services/QuantitativeResearch-因此,将重定向Expertise目录,但不会重定向URL的QuantitativeResearch部分。

I've tried changing it to RedirectMatch301, but it doesn't help. 我尝试将其更改为RedirectMatch301,但这无济于事。 I'm wondering if I need to strip out /Expertise/ and use some Regex instead? 我想知道是否需要删除/ Expertise /并使用一些Regex代替? The /Expertise/ part is already being redirected to /services/ by another line: / Expertise /部分已经通过另一行重定向到/ services /:

Redirect 301 /Expertise/ /services/

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. 为了澄清,我的重定向全部在RewriteEngine On之后和之前进行。

Thanks in advance! 提前致谢!

You do need to use regex based matching here. 您确实需要在此处使用基于正则表达式的匹配。 Try RedirectMatch instead: 请尝试使用RedirectMatch

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

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

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

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