繁体   English   中英

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

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

我正在尝试将一堆URL从旧站点重定向到闪亮的重新启动的站点。 我的.htaccess使用的是第一级目录(即example.com/directory重定向到example.com/newdirectory),但是在该目录下重定向时遇到了问题。 这是一个不起作用的示例:

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

这将转到example.com/services/QuantitativeResearch-因此,将重定向Expertise目录,但不会重定向URL的QuantitativeResearch部分。

我尝试将其更改为RedirectMatch301,但这无济于事。 我想知道是否需要删除/ Expertise /并使用一些Regex代替? / Expertise /部分已经通过另一行重定向到/ services /:

Redirect 301 /Expertise/ /services/

这会引起冲突吗? 我知道我可能在这里错过了一些非常基本的东西! 为了澄清,我的重定向全部在RewriteEngine On之后和之前进行。

提前致谢!

您确实需要在此处使用基于正则表达式的匹配。 请尝试使用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