Justin Rosenthal Justin Rosenthal - 4 months ago 11
PHP Question

Redirect both directory and files within directory

Need to redirect a directory name to one location while directing file paths within that directory to other locations.

In other words:

Redirect /ORIGdirectoryname/ to /Adirectoryname/

Redirect /ORIGdirectoryname/file.php to /Bdirectoryname/

I am finding that if I write:

redirect 301 /ORIGdirectoryname/ http://yourdomain.com/Adirectoryname/


redirect 301 /ORIGdirectoryname/file.php http://yourdomain.com/Bdirectoryname/


http://yourdomain.com/ORIGdirectoryname/file.php


resolves to

http://yourdomain.com/Adirectoryname/file.php


when I want it to resolve to

http://yourdomain.com/Bdirectoryname/

Ben Ben
Answer

It may be the order it is in.

If you can imagine the timeline of events, it will go:

/origdirectoryname/(file here) 301 to /Adirectoryname/

Then it won't trigger the second redirect because it's no longer on origdirectoryname. If you redirected the file first, it would go:

/origdirectoryname/file.php 301 to /bdirectoryname/

Then it would not trigger the redirect from origdirectory to adirectory, as you are now on bdirectory.