Forum Moderators: phranque
I have the following in my htaccess file
RewriteEngine On
RewriteRule ^application\.html$ http://www.domain2.com/app_instructions/index.html [L]
RewriteRule ^registerproducts\.html$ http://www.domain2.com/register_product/index.html [L]
redirectMatch 301 ^(.*)$ http://www.domain2.com
redirectMatch permanent ^(.*)$ http://www.domain2.com
What I'm trying to do is redirect all requests for any URL on domain1 to domain2 except for a few select pages I want to go to selected pages on domain2.
The problem is if a person clicks on application.html or registerproducts.html they are taken to domain2.com instead of http://www.domain2.com/app_instructions/index.html or http://www.domain2.com/register_product/index.html. I thought by placing the [L] after the first two entries that Apache would stop looking for further entries in the htaccess file.
Any help would be appreciated.
John
[edited by: jdMorgan at 12:35 am (utc) on Feb. 21, 2006]
[edit reason] De-linked [/edit]
The main problem is that you're trying to mix directives from two modules; mod-alias and mod_rewrite. This is OK in theory, but if the URLs handled by these two modules' directives are not mutually-exclusive, then there's a problem: You cannot control the order that the modules process their directives it.
To be clear, each Apache module parses your code in turn, and executes the directives that it understands. So while Apache will obey the order that you specify for directives handled within a specific module, the server config determines whether all mod_alias directives are executed followed by all mod_rewrite directives, or vice-versa.
Also, the [L] flag, while stopping mod_rewrite processing for the current pass through your code, has no effect whasoever on mod_alias.
Jim
RewriteRule ^(.*)$ [domain2.com...] [R=permanent,L]
and get the same results except the first two rewrites will work properly?
John
The code then would look like this:
RewriteEngine on
RewriteRule ^application\.html$ http://www.domain2.com/app_instructions/index.html [R=301,L]
RewriteRule ^registerproducts\.html$ http://www.domain2.com/register_product/index.html [R=301,L]
RewriteRule (.*) http://www.domain2.com/$1 [R=301,L]
If you've got a DirectoryIndex directive in domain2/app_instructions and domain2/register_product, then by all means, get rid of the "index.html" in the substitution URLs, and just redirect to <directory_name>/. This keeps the URL shorter, and avoids calling the same file by two names -- /index.html and "/". For reasons why one name is better than two, search for "duplicate content penalty."
Jim