Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect index.html with addon domains

how to redirect index.html to index.php on only the root and not subfolders

         

redtricycle

5:42 am on Feb 7, 2007 (gmt 0)

10+ Year Member



Hi, my current mod_rewrite looks like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress


I'm trying to make:
[abc.com...] redirect to [abc.com...]

However, when I make redirects, the subfolders (addon domains) are affected too, for example:
[blah.com...] redirects to [abc.dom...]

How do I make a rewrite condition and rule that only works for the main domain?
I've tried adding:


# Rewrite /index.html to /index.php for abc.com only
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com
RewriteRule ^index\.html$ /index.php [L]

But that doesn't work.

redtricycle

5:51 am on Feb 7, 2007 (gmt 0)

10+ Year Member



I found what I was looking for at:
[webmasterworld.com...]


RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com
RewriteRule .* - [L]

at the very top will disable the redirect rules

redtricycle

6:03 am on Feb 7, 2007 (gmt 0)

10+ Year Member



Nevermind...
[blah.com...] will still redirect to [abc.com...]

I thought it worked for a second.

Here's what I have:


#This commented code didn't work either
#RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com
#RewriteRule .* - [L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress

# I expect this to ignore the following rule if it's for blah.com
RewriteCond %{HTTP_HOST}!^(www\.)?blah\.com
RedirectMatch permanent ^/index.html$ http://www.abc.com/index.php

jdMorgan

12:40 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks to me as if it's your WordPress code that's doing this; That code will rewrite a request for any file or directory that does not exist to /index.php.

Jim

redtricycle

3:00 am on Feb 8, 2007 (gmt 0)

10+ Year Member



If I put the following at the very top:

RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com
RewriteRule .* - [L]

I expect it to ignore everything below it, especially the:

 RedirectMatch permanent ^/index.html$ http://www.abc.com/index.php 
which is further down.

But I get the same problem: www.blah.com/index.html will redirect to www.abc.com/index.php

[edited by: jdMorgan at 3:17 am (utc) on Feb. 8, 2007]
[edit reason] formatting clean-up [/edit]

jdMorgan

3:16 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's it: RedirectMatch is from an entirely different module -- mod_alias -- and will not be affected in any way by the mod_rewrite exclusion.

If you replace it with


RewriteRule ^index\.html$ http://www.abc.com/index.php [R=301,L]

then the exclusion will apply.

Each Apache module in turn parses your .htaccess file, executing only the directives that it understands. As such, very little 'communication' is available between these modules, and the order of directives from different modules in your code has no effect on the order in which they will be processed. Rather, directives all of the same module will be processed in order, but the directives from differing modules will be processed in the order that those modules execute -- as determined by the inverse LoadModule order on Apache 1.x, and by an internal priority scheme on Apache 2.x.

Jim