Forum Moderators: phranque
RewriteCond %{HTTP_HOST} ^ex\-ample\.com$ [NC]
RewriteRule ^(.*)$ http://www.ex-ample.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?ex(\-)?ample\.(nl¦be¦eu)(.*)$ [NC]
RewriteRule ^(.*)$ http://www.ex-ample.com$4 [L,R=302]
The intention is to 302 redirect all hits from country specific TLD's to their counterparts on the .com TLD by retaining the path after the FQD. For example:
http://ex-ample.nl/ => http://www.ex-ample.com/
http://www.ex-ample.be/ => http://www.ex-ample.com/
http://ex-ample.be/vastgoed-development/lotus-breeze => http://www.ex-ample.com/vastgoed-development/lotus-breeze
However, the path (for instance /vastgoed-development/lotus-breeze) always seems to be lost during the redirect. Does anyone know why?
[edited by: jdMorgan at 6:46 pm (utc) on Oct. 22, 2008]
[edit reason] example.com [/edit]
RewriteCond %{HTTP_HOST} ^ex-ample\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.ex-ample\.com(\.¦\.?:[0-9]+)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?ex-?ample\.(nl¦be¦eu) [NC]
RewriteRule (.*) http://www.ex-ample.com/$1 [R=301,L]
Note that a 302 is no longer used, so as to avoid damaging the search engine ranking of www.ex-ample.com; Using 302's would cause the search engine to "302-hijack" the URLs from www.ex-ample.com, and that is something you do not want to happen.
If it is the case that no other domains or subdomains exist in this .htaccess file's filespace on this server, then this simpler code can be used:
RewriteCond %{HTTP_HOST} !^(www\.ex-ample\.com)?$
RewriteRule (.*) http://www.ex-ample.com/$1 [R=301,L]
Replace the broken pipe "¦" characters in the code above with solid pipes before use: Posting on this forum modifies the pipe characters.
Jim
[edited by: jdMorgan at 12:48 pm (utc) on Oct. 22, 2008]
Thank you very much, this seems to work, although I don't really understand which "problems and inefficiencies" you're talking about exactly. Could you please clarify how these new rules work exactly and why they're more efficient than the old rules? Perhaps walk me through the steps of what happens when someone loads [ex-ample.be...] using these rules.
Also, why wouldn't I want the .com URLs to be hijacked by my ccTLD URLs? That's exactly what I do want to happen, like described in an article I read: "Question: I have an existing .com site and I just bought a ccTLD.
Answer 1: Use a 302 redirect from the ccTLD to the .com. This tells the search engine that your ccTLD is the "real" domain and that it's being temporarily redirected to the .com. The search engine will index the .com, but keep the ccTLD as the "original" domain. In short, the .com won't be considered."
Thanks again
RewriteCond %{HTTP_HOST} ^ex\-ample\.com$ [NC]
RewriteRule ^(.*)$ http://www.ex-ample.com/$1 [L,R=301]
#
RewriteCond %{HTTP_HOST} ^(www\.)?ex(\-)?ample\.(nl¦be¦eu)(.*)$ [NC]
RewriteRule ^(.*)$ http://www.ex-ample.com$4 [L,R=302]
If only a few duplicates exist, the search engines' de-duplication filters will pick one (they choose, not your choice) and discard the rest (these may appear in Google's supplemental index). If many duplicate domains exists, your site/sites may invoke a penalty, especially if reported by a competitor.
Best practice is to choose a single domain for a given Web site, and 301-redirect any and all other domains purchased for "marketing" or "brand-protection" reasons to that single canonical domain. The "302 ploy" trying to get multiple domains listed with the same content won't fool the search engines for a minute, and there is no upside to using it. If language- or location-based content-negotiation is used (in other words, if these domains are not duplicates because the language varies), then this should be a server-internal "transparent" function; A redirect should not be involved.
For more information, search WebmasterWorld for "duplicate content" -- One particularly good title is "Duplicate Content - Get it right or perish." Another good subject to research would be "302 Hijacking."
A recent thread [webmasterworld.com] in the Google Search News forum enumerates many other non-canonical URL variations that you should also address. That forum is also more appropriate for the SEO aspects of your question. See the "Google Hot Topics" thread pinned at the top of that forum's thread list for more useful information.
References and tutorials for mod_rewrite and regular expressions are available in the Apache Forum Charter (link at top left of this page).
Jim
- Clearing browser cache
- Running ipconfig /flushdns
- Alternating computers and browsers
- Using the other domains
- Adding ?randomstring to the URL
Nothing seems to be helping; I always get a "Internet Explorer cannot display the webpage" or similar message. Any idea what could be causing this?