Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am migrating an older site to a newer one which is using drupal. As part of this I am trying to setup some 301 redirects to the new pages but I am getting some unexpected behavior. I added the following line to my .htaccess file:

redirect 301 /redirect.html http://www.mysite.com/newpage

Unfortunately, what happens is that I get taken to:

http://www.mysite.com/newpage?q=redirect.html

Which of course doesn't load correctly. Any thoughts?

share|improve this question
    
I have a question about your question. Did clean urls configure correctly? –  Frank Robert Anderson Aug 24 '10 at 9:19
    
Clean urls did configure correctly. –  Joe Corkery Oct 7 '10 at 0:50
add comment

4 Answers 4

up vote 2 down vote accepted

So after a bit of searching, I found the answer here. It is similar to danlefree's but slightly diffrent.

<IFModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /

    # custom redirects

    RewriteRule ^redirect\.html$ http://www.mysite.com/newpage [R=301,L]

    # end custom redirects

    ...
</IFModule>

This seems to get the job done.

share|improve this answer
    
If you have answered your own question (which moderately, is perfectly acceptable), you should consider marking your own answer as accepted. This helps other users identify questions that are still unsolved. –  Tim Post Aug 18 '10 at 6:54
    
Ditto! But I still think you should look at my answer ;) –  altCognito Aug 18 '10 at 13:11
    
@Tim Post - I would have accepted my own answer, but it wouldn't let me until the question had been posted for 2 days. –  Joe Corkery Aug 18 '10 at 16:12
1  
Instead of hacking around at the Apache level, consider using an appropriate Drupal module - it gives you a lot more power and flexibility. –  Bevan Aug 19 '10 at 20:48
add comment

Forget .htaccess. Use the global redirect. It gives you the following:

  1. Checks the current URL for an alias and does a 301 redirect to it if it is not being used.
  2. Checks the current URL for a trailing slash, removes it if present and repeats check 1 with the new request.
  3. Checks access to the URL. If the user does not have access to the path, then no redirects are done. This helps avoid exposing private aliased node's.

It simplifies migration of your website slightly, and probably most important, it makes it simple to look up exactly what is being redirected where. (as there is a user interface for it)

Bonus (imagine clippy popping up here)

You seem to be creating something similar to clean URLs. I think you might be interested in pathauto.

share|improve this answer
    
Good suggestion - I was going to recommend Path Redirect for similar reasons. –  Bevan Aug 19 '10 at 20:47
    
I looked into this and it conflicted with the Gallery module we had installed. –  Joe Corkery Aug 20 '10 at 20:44
add comment

Your other rewrite rules are interfering.

Try the following instead:

RewriteEngine on

RewriteRule ^/redirect\.html$ http://www.mysite.com/newpage [L,R=301]

# ... existing rewrites
share|improve this answer
    
Unfortunately, this doesn't seem to be working for me. –  Joe Corkery Aug 18 '10 at 4:20
add comment

We used to Path redirect module for that purpose. It can't handle all powerful things that Mod_rewrite can, but it's done a really nice job for us at preserving old URLs.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.