Forum Moderators: bakedjake

Message Too Old, No Replies

Mod_Rewrite / Redirect Help

         

brc2

7:29 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



I am having difficulty redirecting my existing domain and a recently added domain to their correct locations.

Primary Domain: abc.com
Addon Domain: xyz.com (located in a subfolder named xyz, under abc.com)

Before adding the second domain, I was using the following line to redirect traffic to my phpbb folder...
redirect /index.html [abc.com...]

Now I am unable to access the new, addon domain. All requests to xyz.com are forwarded to [abc.com...] My host says the redirect is to blame.

Ok...here is what I need to achieve.
1. All requests for [abc.com...] or [abc.com...] are directed to [abc.com...] I also want to make sure the path, "http://www.abc.com/phpbb/index.php" still shows in the browser's address bar.

2. All requests for [xyz.com...] or [xyz.com...] are direct to [xyz.com...] and look to the "xyz" subfolder as it's "root".

I attempted adding a mod_rewrite command for the addon domain, but it does not work. Again, as told by host, the redirect is breaking the rewrite

Current .htaccess:
redirect /index.html [abc.com...]

RewriteEngine on
RewriteCond $1!^(xyz.com)/
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.(com好et她rg)))
RewriteRule (.*) /%2/$1 [L]

Thanks for help,
Brian

jdMorgan

8:55 pm on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Brian,

Welcome to WebmasterWorld!

The trick here is to make the redirects/rewrites mutually-exclusive.


# Rewrite /index.html to /phpbb/index.php for abc.com only
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com
RewriteRule ^index\.html$ /phpbb/index.php [L]
#
# Rewrite other domains to subfolders
RewriteCond %{HTTP_HOST} ^(www\.)?(list_of_valid_subfolders)\.(com好et她rg)
RewriteRule (.*) /%2/$1 [L]

Because you are doing this in .htaccess, you must take steps to avoid an "infinite" rewrite loop. This can be done in three ways: By using a specific list of allowed secondary domains, by tagging the subfolders with a unique character as discussed here [webmasterworld.com], or by using a special Posix 1003.2 regular-expressions trick to implement a compare function as described here [webmasterworld.com]. Otherwise, your subfolder rewrite code will loop until the server redirection limit is reached, and then fail.

Jim

brc2

10:22 pm on Apr 4, 2005 (gmt 0)

10+ Year Member



Thanks for your quick reply!
Are you saying to prevent the infinite rewrite, I should modify as follows...

# Rewrite /index.html to /phpbb/index.php for abc.com only
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com
RewriteRule ^index\.html$ /phpbb/index.php [L]
#
# Rewrite other domains to subfolders
RewriteCond %{HTTP_HOST}!^www\.(xyx)\.com
RewriteCond %{HTTP_HOST} ^(www\.)?(xyz)\.(com好et她rg)
RewriteRule (.*) /%2/$1 [L]

I only have one domain that will be forwarded to a subfolder.

Thanks,
Brian

jdMorgan

12:37 am on Apr 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can simplify the second rule, then.

# Rewrite xyz domain to subfolder
RewriteCond %{HTTP_HOST} ^www\.xyx\.com
RewriteCond %{REQUEST_URI} !/xyz/
RewriteRule (.*) /xyz/$1 [L]

Jim

brc2

4:55 am on Apr 5, 2005 (gmt 0)

10+ Year Member



Ok...I made an .htaccess file with the following code.

# Rewrite /index.html to /phpbb/index.php for abc.com only
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com
RewriteRule ^index\.html$ /phpbb/index.php [L]
#
# Rewrite xyz domain to subfolder
RewriteCond %{HTTP_HOST} ^www\.xyz\.com
RewriteCond %{REQUEST_URI}!/xyz/
RewriteRule (.*) /xyz/$1 [L]

Here are my results
[abc.com...] (shows directory structure)
[abc.com...] (shows directory structure)
[xyz.com...] (500 error)
[xyz.com...] (goes to [xyz.com...] rather than [xyz.com,...] but does load the correct index.html file)

I also tried prefacing the code with...
RewriteEngine on
but it did not make a difference.

Thanks for all your help! I wish I could be more informative in my replies.

Brian