Forum Moderators: phranque
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]
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.
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.
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.
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]
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]
Jim
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]