.htaccess redirect only working for part of the URL

此生再无相见时 提交于 2020-01-15 17:48:11

问题


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/

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

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/

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.

Thanks in advance!


回答1:


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

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

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


来源:https://stackoverflow.com/questions/25646268/htaccess-redirect-only-working-for-part-of-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!