Forum Moderators: phranque

Message Too Old, No Replies

Old URL to New URL with htaccess in Drupal

I need some rewriting help in Drupal

         

jabz

4:24 pm on Jun 28, 2007 (gmt 0)

10+ Year Member



Hi everybody.
I have a simple question, regarding the .htacces in Drupal. I want to redirect my users from my old URLs (from the time/ site before I used drupal) to the new URLs in Drupal. Generally I use the following:

Redirect /old-url.php http://www.example.com/new-url

But with my current settings, this does not work and I get redirected to something like this:

http://www.example.com/new-url?q=old-url.php

The reason is this rewrite rule in my .htaccess file:

# Rewrite current-style URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

BUT: I cannot change this rule, otherwise my website does not work properly anymore. Does anyone know, what I can do, to redirect my visitors (and search engines) from my old URL to the new URL without changing this exact (and important) Rule?

Any Idea and Help Is Highly Appreciated!
Thank you very much!
Jab

[edited by: jdMorgan at 5:12 pm (utc) on June 28, 2007]
[edit reason] example.com [/edit]

jdMorgan

5:13 pm on Jun 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This kind of thing can easily happen, depending on your server configuration.

Understand that your .htaccess file is not processed linearly as a 'program' or script would be. Instead, each Apache module parses (scans) it, looking for directives that it knows how to handle. Then the next module does the same, in the reverse order specified by the Apache LoadModule list on Apache 1.x, or in an automatically-determined order on Apache 2.x.

The result of this is that on your server, the mod_rewrite directives are being executed first, and then the mod_alias directives are executed. So first, the internal rewrite is being done, and then the external redirect is being done. This 'exposes' your internally-rewritten paths to the client browser.

The solution is to use only one of these modules to do both the rewrites and the redirects, so that you can implicitly control execution order.

Short answer: Re-code your external redirects using mod_rewrite, and place them ahead of your internal rewrites. :)

Example:


RewriteRule ^old-url\.php$ http://www.example.com/new-url [R=301,L]
...
(Drupal internal rewrites here)

Jim

jabz

5:37 pm on Jun 28, 2007 (gmt 0)

10+ Year Member



Oh man, I have to say: Thank You! You really helped me out with this one. :)

But, for the next step, I need to rewrite my old posts with URLs like:
[domain.com...]

Do you know how to rewrite an URL like that?

Again, thanks a billion,
I really appreciate your help!

Jab

jdMorgan

6:03 pm on Jun 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Changing Dynamic URLs to Static URLs [webmasterworld.com] :)

The examples may not apply at the most detailed level, but the overall scheme is the same.

Jim

jabz

2:26 pm on Jun 29, 2007 (gmt 0)

10+ Year Member



I think this will help me. Thank you....for all your help. :)