Redirecting subdirectory into root, and all pages therein

jnicola's picture

Hey there everyone,

So for a while there I was placing all of my drupal content in a subdirectory, and redirecting all my visitors to the subdirectory. I've come to discover through working with some people who do a lot of SEO work that it's not a good idea to go doing that. So, I moved everything to the root directory from the subdirectory, did abunch of other stuff for SEO, and now I want to redirect everything from the old sub directory back to the root directory.

The question is.... how? I looked a bunch of stuff online up, and can't quite seem to find a way to redirect. I can redirect from the /drupal to the root, but I can't seem to get it to work in a fashion that takes the previous /drupal/user and go to /user. The closest I've come yet in .htacces goes from /drupal/user to /?q=user, which with clean url isn't an option, and I really don't want search engines indexing that over the clean url.

So, anyone have any experience or advice on how to make this work with drupal? I've researched for a good hour and a half now, and haven't had any luck.

Thanks for your time,
Jesse

Login or register to post comments

Jesse Nicola -- My Portfolio

jnicola's picture
jnicola - Sat, 2009-05-23 22:11

Jesse Nicola -- My Portfolio -- MHSS, my main project!


Nevermind, I found the

jnicola's picture
jnicola - Sat, 2009-05-23 22:57

Nevermind, I found the solution, although it wasn't easy to dig up:

Add the following to the .htaccess file AFTER RewriteEngine on

RewriteBase /
RewriteRule ^[SUBDIRECTORY]/(.*)$ /$1 [R=301,NC,L]


You made my day!

BarisW's picture
BarisW - Wed, 2009-07-29 22:24

Thanks @jnicola for sharing this.
I've been searching for hours on strings like 'htaccess redirect directory', 'htaccess path redirect', etc.

But just before giving up i tried 'drupal subdirectory redirect' and voila, the first link on Google.

THANX!


That was a good find Jesse -

pairodime's picture
pairodime - Thu, 2009-06-04 22:04

That was a good find Jesse - using .htaccess is super key to SEO - especially when making major changes to your site architecture.

One thing to keep in mind - is not everything needs to have a 301. I have worked with many clients where we re-structured their site to be more SEO friendly and did not even bother trying to 301 every page. This would mainly be for static websites - thankfully Drupal makes it easy to 301 your whole site because it should match up to the new structure - as Drupal is pretty specific on its architecture.

Good luck with that - if you ever need any other advice - never hesitate to hit me up.