Hi,
We've switched several static sites or far less superior CMS driven sites to Drupal over the past few months. Now we are left with lots of lingering URLs that do not redirect correctly. Esentially, I only want to redirect old folders and everything within them to the homepage of the new, Drupal powered sites.

We have installed pathauto on all of these sites, so I think the lines of code written to the .htaccess file is what has thrown off my attempts at redirecting correctly.

I simply want something like this done. Example:

1) Old folder under root dir. called "/categories/" and everything under/in that folder permanently moved up one level to "/" (main URL path)
2) Old forum path "forum/BB" and everything under/in that folder permanently moved to "/blog"

Right now, an example of one major issue is this, for example:

1) Old URL "/seoposition-sitemap.html" gets redirected to the home page, but this is what the URL looks like now: http://seoposition.com/sitemenu?q=seoposition-sitemap.html

In fact, many of the issues follow the example above, where the "?q=" and then the old url path gets tacked onto the end of the URL after the "?q=."

If anyone understands 301s and pathauto's implications/restrictions, etc., and can help us out, I would be very grateful.

Thanks!

Comments

drshields’s picture

I understand 301's very well. Could you do something like this:

Have 404's go to a specific redirect.php page in the root directory. Then using some built in php functions to figure out what url was trying to be accessed, and 301 redirect to the new url all from within that function? I am in the process of doing that exact same thing right now with a site I'm working on, and so far its worked really well.

---
Redbox Codes
Michael Scott
^- Some of my Dupral Implementations

solipsist’s picture

I did this when I migrated to Drupal. I know this works since my former pages' SE ranking has now carried over to the corresponding pages at my new site. Here's a copy of the relevant code from my .htaccess file, you need to place these rules before the Drupal rewrite rules:

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Modify the RewriteBase if you are using Drupal in a subdirectory and
  # the rewrite rules are not working properly.
  RewriteBase /

  # custom redirects for old URLs
  # section pages
  RewriteRule ^templates.php$ http://www.jakob-persson.com/templates [R=301,L]
  RewriteRule ^portfolio.php$ http://www.jakob-persson.com/portfolio [R=301,L]
  RewriteRule ^who.php$ http://www.jakob-persson.com/about [R=301,L]
  RewriteRule ^download/$ http://www.jakob-persson.com/downloads [R=301,L]
  RewriteRule ^download$ http://www.jakob-persson.com/downloads [R=301,L]
  RewriteRule ^download/pafiledb.php$ http://www.jakob-persson.com/downloads [R=301,L]
  RewriteRule ^books.php$ http://www.jakob-persson.com/webstore [R=301,L]
  RewriteRule ^contact.php$ http://www.jakob-persson.com/contact [R=301,L]
  RewriteRule ^guestbook.php$ http://www.jakob-persson.com/guestbook [R=301,L]

  # other pages
  RewriteRule ^styles_demo_forum/index.php(.*) http://www.jakob-persson.com/styles_demo/index.php$1 [R=301,L,NC]
  RewriteRule ^styles_demo_forum/(.*) http://www.jakob-persson.com/styles_demo/phpBB2/$1 [R=301,L,NC]  
  RewriteRule ^styles_demo.php$ http://www.jakob-persson.com/styles_demo/ [R=301,L]
  RewriteRule ^faq.php$ http://www.jakob-persson.com/faq [R=301,L]
  RewriteRule ^donate.php$ http://www.jakob-persson.com/donate [R=301,L]
  RewriteRule ^omcookies.php$ http://www.jakob-persson.com/cookies [R=301,L]

If you need help with it, let me know.

--
Jakob Persson
web design and usability consulting
http://www.jakob-persson.com

--
Jakob Persson - blog
Leancept – Digital effect and innovation agency

andre75’s picture

Redirects are fairly easy:

RewriteCond %{REQUEST_URI} ^.+.+taxonomy.*$
RewriteCond %{REQUEST_URI} !^.*admin.*$
RewriteRule ^.*taxonomy(.*)$ http://www.example.com/taxonomy$1 [R=301,L]

I created the one above for google. there was some problem with the base url and google was looking for:
example.com/somestring/taxonomy/someotherstring

The first line checks for the string taxonomy with at least two other characters in front of it and some undetermined number after.
The second excludes everything like example.com/admin/taxonomy from the rewrite
The third one redirects everythign with
example.com/simestring/taxonomy/someotherstring to example.com/taxonomy/someotherstring

I think in your example you are using [QSA] (query string append), but I am not really sure what it is that you want.

1) this should take care of problem 1

RewriteCond %{REQUEST_URI} ^categories.*$
RewriteRule ^.*categories(.*)$ http://www.example.com/$1 [R=301,L]

2)

RewriteCond %{REQUEST_URI} ^forum\/BB.*$
RewriteRule ^.*forum\/BB(.*)$ http://www.example.com/blog/$1 [R=301,L]

I am not 100% sure about the RewriteCond. Maybe you have to add .+ after each ^ in order to account for the slash.
You should be able to ommit the line RewriteCond, but you can use it to set up exceptions like the admin pages in my example above.

It is also wise to redirect non-www urls to www urls (or vice versa), since google doesn't like two domains.
I use this:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

Hope this helps. I don't want any money.

Andre

-------------------------------------------------
http://www.opentravelinfo.com
http://www.aguntherphotography.com

jjeff’s picture

I've got a module in the works that handles redirecting any Drupal path to any internal or external URL with any redirect code of your choosing.

I'm still putting the finishing touches on it, but I hope to commit it in the next few weeks.

--= Jeff Robbins | www.lullabot.com =--

mactoph’s picture

It sounds like this might be able to do the same thing as Steve Smith's Wordpress Feedburner Plugin- that is it could allow the url of your feed www.yoursite.com/feed to point to a feedburner feed (http://feeds.feedburner.com/yourfeed)- correct?