Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite questions

bit complex

         

fade24

2:22 pm on Jul 18, 2010 (gmt 0)

10+ Year Member



Hi,

I have been getting a bit stuck with my mod rewrites and was wondering if anyone could help me.

I have 2 domains

abc.com
xyz.com

abc.com is the main domain with xyz.com being an addon domain.

Both urls function the same e.g. abc.com/index.php is the same as xyz/index.php

The problem I have is my forums will only run off of abc.com
so abc.com/forums
but you can still get to them via xyz.com/forums
which throows up a few errors.

What I would like to do is to redirect anyone that goes to xyz.com/forums to abc.com/forums and only anyone that goes to this subfolder or folders with in it.

But, I am a little stuck on how to do this?

Any ideas?

lammert

2:40 pm on Jul 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi fade24, first of all Welcome to WebmasterWorld!

Before going into detail about a possible solution for your situation, have you considered to redirect all traffic from the domain xyz.com to abc.com? I am not asking this without reason. Search engines--especially Google--use algorithms to detect pages which are almost equal and remove all but one from these almost-equal instances from their index. This is called the duplicate content issue. Duplicate content problems may lower the visibility of both abc.com and xyz.com in the search engines, something which you probably don't want.

If you don't have specific reasons to let both abc.com and xyz.com exist as a life domain, I would propose you to redirect all URLs from xyz.com to abc.com, not only the /forums part.

fade24

4:57 pm on Jul 18, 2010 (gmt 0)

10+ Year Member



Hi Lammert. I am not too worried about seo but, thanks for that.

I do have some ratehr complex reasons as to why I want the domains to work this way. Mainly due to licensing issues but, also just a personal preference on how it operates.

g1smd

5:20 pm on Jul 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Whatever you do, forums, or whole site, you'll need just one or two lines of code to fix it.

One question, do you want to redirect both www and non-www of the non-canonical domain, and the non-www of the canonical domain, all to the www of the canonical domain? That would likely be the best option.

fade24

5:34 pm on Jul 18, 2010 (gmt 0)

10+ Year Member



Hi G1smd, Yes i want to redirect the www of the xyz and the non www of the xyz but again only for that one subfolder /folders to the /folders on abc if that all makes sense

jdMorgan

8:28 pm on Jul 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not clear whether you're specifying URL-paths or filepaths above, and the distinction is important, but assuming that your "xyz" site resides in the same filespace as "abc.com" but in a subdirectory called "/xyz" below the main "abc.com" files, and that you have other working mod_rewrite rules in place, then in .htaccess in /xyz/ (i.e. in the top-level directory for xyz.com):

# Redirect all xyz.com/forums/<whatever> requests to www.abc.com/forums/<whatever>
RewriteRule ^forums(/.*)?$ http://www.abc.com/forums$1 [R=301,L]
#
# Redirect any requests for non-canonical xyz.com hostnames
# to the canonical www.xyz.com hostname
RewriteCond %{HTTP_HOST} ^([^.]+\.)*xyz\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.xyz\.com$
RewriteRule ^(.*)$ http://www.xyz.com/$1 [R=301,L]

and in /.htaccess (i.e. in the top-level directory for "abc.com")

# Redirect all direct client requests for /xyz/forums/<whatever>
# in any domain to www.abc.com/forums/<whatever>
RewriteCond THE_REQUEST ^[A-Z]+\ /xyz/forums([/#?][^\ ]*)?\ HTTP/
RewriteRule ^xyz/forums(/.*)?$ http://www.abc.com/forums$1 [R=301,L]
#
# Redirect all direct client requests for /xyz/<whatever>
# in any abc.com domain to www.xyz.com/<whatever>
RewriteCond THE_REQUEST ^[A-Z]+\ /xyz([/#?][^\ ]*)?\ HTTP/
RewriteRule ^xyz(/.*)?$ http://www.xyz.com$1 [R=301,L]
#
# Redirect any requests for non-canonical abc.com hostnames
# to the canonical www.abc.com hostname
RewriteCond %{HTTP_HOST} ^([^.]+\.)*abc\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.abc\.com$
RewriteRule ^(.*)$ http://www.abc.com/$1 [R=301,L]

Again, this code's applicability depends on having a standard "add-on-domain" setup, where the add-on domain is stored in a subdirectory below the main site's files. Also, I do not show the required 'set-up and enable' code for using mod_rewrite, as I assume that you already got some working rules in these .htaccess files.

The code snippets above should be inserted ahead of any existing internal rewrite rules, according to the following rule of thumb:

"Put all external redirects first, in order from most-specific to least-specific patterns and conditions -- in other words, ordered from rules that affect only one or a few URLs to rules that affect many URLs. Follow all external redirect rules with all internal rewrite rules, again in order from most- to least-specific."

Adhering to this rule prevents all kinds of unintended consequences, such as stacked or chained (multiple) redirects, and/or exposing your internal filepaths as URLs to HTTP clients, either of which can negatively affect your pages' rankings in search and confuse humans as well.

Jim

fade24

9:49 pm on Jul 18, 2010 (gmt 0)

10+ Year Member



Hi Jdmorgan,

Thanks for that, I am going to give it a test and will report back. I think I am going to have to modify it a bit but will let you know (there ix no xyz folder so i guess my webhost is not doing it in the standard format)

jdMorgan

10:15 pm on Jul 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The whole thing hinges on a standard set-up.

If your set up is not as described, then a major-rework will be needed, and we'll need an accurate description of how your sites are stored in the server filespace.

Jim