Internet Marketing, SEM, News, Sports, Videos, and Politics Blog
Redirecting All Traffic From A Subdirectory To The Root
If you want to permanently redirect all the traffic from a subdirectory to the root domain, and you’re running Apache, the job is quite simple. All you need to do is make sure you mod_alias installed, and then you can a simple command to your .htaccess file.
Here’s example code.
RedirectMatch 301 ^/old/(.*)/$ http://www.newdomain.com/$1/
That would take all the requests for files located in the /old/ directory and redirect them permanently their new location at the root. This might come in handy for someone who has a blog installed in a subdirectory and wants to promote it to the root.
You can also exclude directories, in case you need to. Use the following syntax:
Redirect permanent ^/(?!category/)(?!tag/)(.*)/(.*)/$
Redirect match supports regex so anything that can be done in regex can be done using redirectmatch. The documentation from Apache is typically obtuse.
“This directive is equivalent to Redirect, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.”
In any event, redirectmatch is an extremely powerful and easy to use way to do redirection.
| Print article | This entry was posted by Darren on December 22, 2008 at 5:16 pm, and is filed under SEM. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |