Forum Moderators: phranque
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]
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
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
The examples may not apply at the most detailed level, but the overall scheme is the same.
Jim