301 redirect for all combinations

Hello everyone,

I have made a change to my site so that it is no longer in a subdirectory of my root domain. (it is now in the root of the domain).

I have made the move successfully but I would like to put a 301 redirect into my htaccess so that people visiting the old links make it to the new site.

A sample link on my site has gone from www.mysite.com/olddirectory/samplelink to www.mysite.com/samplelink

So basically, I am looking for something that would say if any one goes to www.mysite.com/olddirectory/wildcard_here they would be redirected to www.mysite.com/wildcard_here .

On another site, I was doing something similar but in the other direction. I had moved a site into a directory from the root, so I had

RewriteEngine on 
RewriteCond $1 !^newdirectory 
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

Is there any way to do what I am trying to do? It is important that if some one goes to a directory that is not “olddirectory”, they should not be redirected.

Thank you in advance

Thank you for the reply.

The problem I am having is that I have thousands of urls within the olddirectory.

As far as I can tell, this solution only works for people going directly to the root of /olddirectory. Am I correct in that statement?


Thank you for the help!

You were correct in your assumption that I did not try your suggestion. At the time, I did not have access to my ftp, so I could not try it. I did however read the link you provided, I was just confused as there was no wildcard apparent in the redirect, so I did not expect it to work.

I have now tested it and it is working perfectly! Thank you for your help!


That’s so simple that you don’t even need mod_rewrite to do that! Look at Apache’s mod_alias which should get you to:

Redirect permanent /olddirectory http://example.com/

As a webmaster (just as a carpenter), using the correct tool for the occasion is important!





If you’re still confused, PLEASE ask questions as it’s important to me that you know WHY things work (so you can help others learn when you get the chance).




Did you try it? Okay, obviously not! From that response, I’m sure you didn’t even go look at the Apache.org page! Oh, well, when you do, you’ll learn that mod_alias will work on that directory as specified (removing it from the URLs with a permanent redirection).