Forum Moderators: phranque
I'm moving a sub-domain to a new FQDN I just bought.
This works for me:
Redirect 301 / http://www.example.org/
But this does not:
Redirect 301 /health-and-diet/puppies-and-worms.php http://www.example.org/health-and-diet/puppies-and-worms/
Instead of redirecting to the directory "puppies-and-worms" - it tries to add the file name:
http://www.example.org/health-and-diet/puppies-and-worms/puppies-and-worms.php
What am I doing wrong?
[edited by: jdMorgan at 2:40 am (utc) on Dec. 22, 2007]
[edit reason] example.org. Please see TOS. [/edit]
RewriteEngine On
Redirect 301 / http://www.example.org/
Redirect 301 /dog-blog/ http://www.example.org/
Redirect 301 /health-and-diet/ http://www.example.org/health-and-diet/
Redirect 301 /health-and-diet/puppies-and-worms.php http://www.example.org/health-and-diet/puppies-and-worms/
Redirect 301 /resources/articles.php http://www.example.org/resources/pet-articles/
Redirect 301 /resources/spay.php http://www.example.org/resources/spay-and-neuter/
Redirect 301 /resources/contact.php http://www.example.org/contact/
Redirect 301 /training-articles/ http://www.example.org/training-articles/
The redirects from the old directories to the new directories work, but the ones that have filenames (.php) don't. They all add the filename.php to the redirected URL.
Thanks in advance!
[edited by: jdMorgan at 2:36 am (utc) on Dec. 22, 2007]
[edit reason] example.org [/edit]
It's actually doing what the Redirect directive in mod_alias usually does, even within the same site. You might want to give RedirectMatch a whirl and see if it'll work for you. The RedirectMatch directive supports regular expressions, and is the equivalent, but the Redirect directive (which is what you're now using) doesn't support them.
[stanford.edu...]
Syntax:
RedirectMatch [status] regex URL
It can't hurt to give it a try, it's just another tool that's available and they're all different.
From the forum library:
Regular Expressions [webmasterworld.com]
I know, I know: arrggghhhhh! :)
[edited by: Marcia at 2:32 am (utc) on Dec. 22, 2007]
The Redirect directive uses prefix-matching. Therefore, your less-specific whole-directory Redirect directives will always be invoked because they come first in your posted code, and the more-specific per-file ones won't ever be invoked.
[added] ... and the domain redirect --currently your first Redirect directive-- should be the last one, because it will match *all* URLs, and redirect them to the same URL on the new domain. Always order your redirects and rewrites from most-specific (longest URL-path) to least-specific. [/added]
Jim
[edited by: jdMorgan at 2:44 am (utc) on Dec. 22, 2007]
The code above would probably work if you put the most-specific directives first -- i.e. put the Redirect including the .php filename ahead of the one for that same directory.
Redirect 301 /dog-food-recall/ http://www.example.org/resources/dog-food-recall/
Here's the newly ordered .htaccess:
RewriteEngine On
Redirect 301 /health-and-diet/puppies-and-worms.php http://www.example.org/health-and-diet/puppies-and-worms/
Redirect 301 /health-and-diet/ http://www.example.org/health-and-diet/
Redirect 301 /resources/articles.php http://www.example.org/resources/pet-articles/
Redirect 301 /resources/spay.php http://www.example.org/resources/spay-and-neuter/
Redirect 301 /resources/contact.php http://www.example.org/contact/
Redirect 301 /training-articles/ http://www.example.org/training-articles/
Redirect 301 /dog-food-recall/ http://www.example.org/resources/dog-food-recall/
Redirect 301 /dog-blog/ http://www.example.org/
Redirect 301 / http://www.example.org/
Thanks all of you! Any thoughts on this last one?
[edited by: jdMorgan at 4:03 am (utc) on Dec. 22, 2007]
[edit reason] example.org. Please see Terms of Service. [/edit]
But here's what I just tried for redirecting all of the individual files in a /directory/ to a subdirectory on another site without specifying any individual pages, using just one line of code:
RedirectMatch ^/directoryname/(.*)\.html http://www.example.com/subdirectory/
After three 500 Internal Server Errors, it's working just fine, redirecting for all the files within the directory. They all go to the root of the subdirectory on the other site.
Added: That gives a 302. This way gives a 301:
RedirectMatch 301 ^/directoryname/(.*)\.html http://www.example.com/subdirectory/
[edited by: Marcia at 4:03 am (utc) on Dec. 22, 2007]