问题
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