Forum Moderators: phranque

Message Too Old, No Replies

Search engine mess

Redirection of domains

         

geekay

2:43 pm on Apr 4, 2004 (gmt 0)

10+ Year Member



This is a desired further development of Jim's working final code (see below) in thread [webmasterworld.com...] It is a case of several domains pointing to the same spot. I wanted requests for some domains to redirect to a main domain, leaving two 'separate' sites, a and c.

Unfortunately my actions came too late, and now the 'other' search engine has indexed pages belonging to site cccc.com under the domain of bbbb.com. This is bad both visually and with regard to SEO. Is it possible to solve this problem with mod_rewrite? I have tried hard, but nothing works.

The problem pages are all in their own directory /sub1/. The other pages found by the SE under bbbb.com all belong to the root, and they are now being redirected properly by mod_rewrite. But pages in /sub1/ do not get their domain changed (i.e. showing up in browser as bbbb.com/sub1/xyz.html instead of cccc.com/sub1/xyz.html).

RewriteRule ^sub1存ub2 - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?cccc\.com [NC]
RewriteRule (.*) /sub1/$1 [L]
RewriteCond %{HTTP_HOST} ^((www\.)?(bbbb圬ddd)地aaa)\.com [NC]
RewriteRule (.*) [aaaa.com...] [R=301,L]

jdMorgan

6:34 pm on Apr 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your first rule explicitly tells mod_rewrite to quit if /sub1 or /sub2 is requested. Therefore, /sub1 is not redirected...

Jim

geekay

5:10 am on Apr 5, 2004 (gmt 0)

10+ Year Member



Yes, but changing the first part of the first rule to "cccc.com/sub1" only results in requests for bbbb.com/sub1 being served as aaaa.com/sub1. I cannot get the pages served as cccc.com/sub1. Unfortunately HTTP_HOST does not seem to work when a directory is included in the condition test. REQUEST_URI does not change the domain name in the browser address bar.

Maybe there is no mod_rewrite solution? If I put as first a new condition HTTP_HOST bbbb.com and a new rule aaaa.com/error/, all request containing bbbb.com are redirected to either folder /errror/ or /error/sub1/. (sub1 is the only folder that occurs with bbbb.com and only sub1 files are causing problems.) In those two folders I put empty pages with the names of all files that can occur. Then I have on each page a meta refresh or a clickable link to the right file. Very amateurish indeed, and not user or SE friendly, even though I include a noindex attribute.

jdMorgan

5:32 am on Apr 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem here is that hostnames, such as your cccc.com must be tested with RewriteCond %{HTTP_HOST} and subdirectory URL-paths must be tested with either RewriteCond %{REQUEST_URI} or with the RewriteRule itself; You cannot test hostnames directly in a RewriteRule.

Your problem is complex enough that no-one here is likely to remember all the details and all the changes that have been made. I suggest you make a complete list of exactly what groups of hostname/subdirectory combinations need to be *rewritten or redirected, and where you want to rewrite or redirect them to. By creating a 'map' of your problem in this format you will find it easier to write rules to effect the rewrites and redirects that you need. Defining the problem precisely is 99% of the work.

Speaking of 99%, I am at least 99% certain that yes, you can fix your problem with mod_rewrite.

Jim

* A rewrite changes the filepath inside the server from which content is served. It does not change the client browser's address bar. A redirect sends a new URL to the client browser, and tells it to re-request the desired content from that new URL. When the client browser issues this new request, it updates its address bar. In mod_rewrite RewriteRules, a redirect typically specifies a canonical URL (http://www.example.com...) and has an [R] flag appended, whereas a rewrite specifies a local path and has no [R] flag.

geekay

11:04 am on Apr 5, 2004 (gmt 0)

10+ Year Member



Jim's excellent code in my post #1 would be all I need, if I only had known it before that SE indexed my pages with wrong domain. Their results look really silly now. 301 Redirects would slowly correct SE results. The problem files are less than 20, so even listing all their full paths would be possibly. But in HTTP_HOST I can only use the plain domain name, and REQUEST_URI does not change the domain name in the browser address bar.

If only the first rule in Jim's code could be supplemented to do the following:
"If the request contains sub1存ub2 then quit, unless the request is for bbbb.com/sub1/." (It could of course also read: if the request is for anything else than cccc.com/sub1存ub2/, then follow a rule, but that could complicate matters further. No other domain than bbbb.com is messing up - so far...)
Next: "if the request was for bbbb.com/sub1/, then serve cccc.com/sub1/".

My 'emergency' redirect in msg #3, "condition HTTP_HOST bbbb.com, rule aaaa.com/error/", is actually too simplified and global. Jim's code would already have redirected requests for bbbb.com/xyz.html to aaaa.com/xyz.html, just as it preferrably should be done. The problem is really that requests for pages in directory sub1 should never be served with the domain bbbb.com visible in the browser address bar, only with cccc.com.

geekay

12:14 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



I want to warn others that my 'emergency' redirect does not work. I just learned that, for some strange reason, www.cccc.com/sub1/ or any of the other files in directory sub1 cannot be found, unless the first two lines in the code below is omitted. Maybe it is the order of the rules.

RewriteCond %{HTTP_HOST} ^(www\.)?bbbb\.com [NC]
RewriteRule (.*) [aaaa.com...] [R=301,L]
RewriteRule ^sub1存ub2 - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?cccc\.com [NC]
RewriteRule (.*) [cccc.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^((www\.)?(bbbb圬ddd)地aaa)\.com [NC]
RewriteRule (.*) [aaaa.com...] [R=301,L]

jdMorgan

6:35 pm on Apr 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"If the request contains sub1存ub2 then quit, unless the request is for bbbb.com/sub1/."

Equivalently, "If the request contains sub2 then quit" and "If the request contains sub1 and not bbbb.com then quit."


RewriteRule ^sub2 - [L]
RewriteCond %{HTTP_HOST}!^(www\.)?bbbb\.com [NC]
RewriteRule ^sub1 - [L]

As I said, breaking down the various cases into a basic list makes understanding it much easier. Make a comprehensive list first, re-arrange it by common desired action, and then code it efficiently.

Jim

geekay

9:42 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



That solved the error mentioned in msg #6. But next Apache has to do something if the request is for bbbb.com. The goal is:
"If the request is for bbbb.com/ (and some file) then quit, but if the request is for bbbb.com/sub1/ then deliver cccc.com/sub1/."
If I only could write a line:
RewriteCond %{HTTP_HOST} ^(www\.)?bbbb\.com/sub1/
but that is illegal.

Is there anything cleverer than my 'emergency' solution from msg #3?:

RewriteRule ^sub2 - [L]
RewriteCond %{HTTP_HOST} !^(www\.)?bbbb\.com [NC]
RewriteRule ^sub1 - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?bbbb\.com [NC]
RewriteRule (.*) [aaaa.com...] [R=301,L]