Justin Rosenthal Justin Rosenthal - 7 months ago 28
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/


resolves to


when I want it to resolve to


Ben Ben

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.