Forum Moderators: phranque
I've had a few 301 redirects in place for a number of years now, but late last year I also needed to introduce a rewrite to get around canonical problems with G. The relevant contents of .htaccess are:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteRule ^(.*)$ [site.com...] [L,R=301]
and:
redirect 301 /folder/file.htm [site.com...]
.. so what's happening now is that if there's a request for
[site.com...]
I wind up with 2 301 responses before the correct page is fetched, first the rewrite to www and then the redirect to the correct page.
I've tried putting the
redirect 301
line first in .htaccess, but the same issue occurs. Is there a way around this double 301 effect?
Thanks in advance for your assistance!
Each of those modules will parse your .htaccess file in turn, executing the directives that it understands, with the order determined by the server configuration. Therefore, it makes no difference what order yo put your two directives -- re-arranging them does not change their execution order.
This applies to all other directives in config files -- You cannot control order of execution on a per-directive basis unless those directives are all implemented in the same module. The module execution order is set by the reverse LoadModule order in Apache 1.x, and by an internal priority scheme in Apache 2.x
The solution is to use either mod_alias or mod_rewrite, but not both, for sequence-critical rewrites and redirects. Since mod_alias cannot do conditional redirects and cannot do internal rewrites, I'd suggest using mod_rewrite for your folder redirect.
Jim
As always, thank you :)
I've just tried (after removing the mod alias rule)
Options +FollowSymLinks
RewriteEngine on
rewriteRule ^/folder/file\.htm$ [site.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteRule ^(.*)$ [site.com...] [L,R=301]
and also as a separate entry:
rewriteEngine on
rewriteRule ^/folder/file\.htm$ [site.com...] [R=301,L]
(tried both above and below the http:// to [www...] rule)
.. but I just wind up with a 404 as the http:// to [www...] rule kicks in first, and the other rule is ignored - could you please advise as to where I'm going wrong?
Options +FollowSymLinks
RewriteEngine on
#
RewriteRu[b]le ^fo[/b]lder/file\.htm$ http://www.example.com/folder/file2.htm [R=301,L]
#
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]