Forum Moderators: phranque
I am using an .htaccess file to keep a set of permanent redirects after migrating from static html to a CMS with Drupal.
I have an .htaccess (heavily snipped) as such:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
redirect 301 /html/001.html [mysite.com...]
It worked properly making:
[mysite.com...] into [mysite.com...]
But after upgrading Drupal, the final URL becomes:
[mysite.com...] and that gives a 404 error.
If I coment the lines:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
The redirection works to [mysite.com...] but the system runs amok and becomes unusable.
I am stuck. This must be pretty simple, but I don't get it: How can avoid htaccess rewriting my redirections in such a way, please?
Thanks a lot :)
[edited by: Gusgsm at 10:03 pm (utc) on Jan. 3, 2007]
Apache modules parse your .htaccess file(s) one-by-one, with each module handling the directives that it recognizes. Thus the execution order of directives addressed to different modules depends on the module execution order, controlled by the server configuration, not on the oredr that you place them in the file.
So first up, I'd change the code to use mod_rewrite only, and reverse the rules.
RewriteRule ^html/001\.html$ http://www.example.com/blah_blah [R=301,L]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteRule ^html/001\.html$ http://www.example.com/blah_bl[b]ah?[/b] [R=301,L]
Jim
001.html is a real file that lives in a subfolder called "html", so [mysite.com...] is really real. And the [mysite.com...] is the typical url I have. Truly.
That's why I don't understand the change you point . Shouldn't it be (then)?
RewriteRule ^html/001.html http://www.example.com/blah_blah [R=301,L]
Sorry :)
"^" indicates that the requested URL-path must *start with* the character or pattern which follows it.
"$" indicates that the requested URL-path musr *end with* the character or pattern which precedes it.
RewriteRule cannot 'see' query strings appended to the URL-path, so a pattern ending with "\.html$" is usually used when URL-paths with .html extensions are being matched.
The meaning of blah_blah could be:
...or any of a number of other possibilities. It is difficult to answer questions about generalized path descriptions, because mod_rewrite can handle all of these possibilities, and the code must correspond exactly to the one you really want.
Sorry if I was or am being abrupt -- I often have to type fast to keep up.
Jim
The perfect redirection was:
RewriteRule ^html/001\.html$ [mysite.com...] [R=301,L]
Thaaaaankkkk youuuu! :)
[edited by: Gusgsm at 7:22 pm (utc) on Jan. 4, 2007]