Forum Moderators: phranque

Message Too Old, No Replies

.htaccess conditional redirect domain to subdomain

on multi-language site with shared root folder

         

guum

10:30 am on May 6, 2010 (gmt 0)

10+ Year Member



My website has two languages: 'www.example.com' is English and 'de. example.com' German. Domain and Subdomain point to the same root folder and only the configuration say that the domain is English and then load the English content from db.

Problem: if a link point to a German page on Domain (where English default language is), the CMS shown for now German content. What I want is redirect to the subdomain.

www.example.com/en-folder/*
OK

www.example.com/de-folder/*
Wrong -> must redirect to:
de.domain.com/de-folder/*

As I have two root folders for domain and subdomain, was easy to redirect:
redirectmach .../de-folder/… http://de.example.com/de-folder/..
but now with only a root folder for bots domain and subomain, this generate a loop.
(.htaccess don't know include file)

Question:

It is possible such a rule?

If URL www.example.com and URL request /de-folder/* redirect to de.domain.com/de-folder/*
If URL de.example.com and URL request /en-folder/* redirect to www.domain.com/en-folder/*

If URL www.example.com and URL request /de-folder.html redirect to de.example.com/de-folder.html
If URL de.example.com and URL request /en-folder.html redirect to www.example n.com/en-folder.html

Redirect work fine:
/folder / http://de.example.com/ folder/..

But must first check if the URL is www.example.com or de.example.com
Rule and then something like break because now must redirect vice versa.

Thanks in advance

[edited by: jdMorgan at 4:57 pm (utc) on Jun 20, 2010]
[edit reason] De-linked [/edit]

jdMorgan

3:54 pm on May 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no need to 'expose' either the 'en-folder' or the 'de-folder' *filepath* in the URL. It is wasted bytes.

Instead, remove "en-folder/" and "de-folder/" from your on-page links, use only the "www" and "de" subdomains in on-page links which are used to change between languages, and try something like this:

Language -- hostname --------- server-internal filepath
English ---- www.example.com - /en-folder
Deutsche -- de.example.com --- /de-folder

# External Redirects
#
# Redirect direct client requests for language-folders to canonical hostname
# for that language. (In this implementation, language-folders in the requested
# URL-path take precedence over the requested language-specific hostnames.)
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /de-folder/[^\ ]*\ HTTP
RewriteRule ^de-folder/(.*)$ http://de.example.com/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /en-folder/[^\ ]*\ HTTP
RewriteRule ^en-folder/(.*)$ http://www.example.com/$1 [R=301,L]
#
# Redirect to force canonical hostnames. Any requested hostname which contains "de."
# but is not exactly equal to "de.example.com" is redirected to de.example.com. Any
# requested hostname which is not blank and is not exactly equal to "www.example.com"
# or "de.example.com" is redirected to "www.example.com"
#
# Redirect non-canonical hostname requests or requests to canonical hostnames
RewriteCond %{HTTP_HOST} ^([^.]+\.)*de\.([^.]+\.)*example\.com [NC]
RewriteCond %{HTTP_HOST} !=de.example.com
RewriteRule ^(.*)$ http://de.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteCond %{HTTP_HOST} !=de.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
#
# Internal Rewrites
#
# For de.example.com, rewrite all requests to /de-folder/ if not already done
RewriteCond %{HTTP_HOST} =de.example.com
RewriteCond $1 !^de-folder/
RewriteRule ^(.*)$ /de-folder/$1 [L]
#
# For www.example.com, rewrite all requests to /en-folder/ if not already done
RewriteCond %{HTTP_HOST} =www.example.com
RewriteCond $1 !^en-folder/
RewriteRule ^(.*)$ /en-folder/$1 [L]

Note that the "extra complication" in the first RewriteCond of the canonicalization rule for the English "www" subdomain is intended to disable the redirect if a blank hostname is requested by an HTTP/1.0 client. While this is not a very likely occurrence, an infinite loop would result without that provision.

Use of RewriteConds to test THE_REQUEST is what prevents the first two redirects from looping with the last two rewrites. Checking THE_REQUEST ensures that the /de-folder and /en-folder were directly requested by the client (browser or robot), and not as a results of internal requests invoked by one of the last two rewrite rules shown here.

Be very careful of the interplay between case-matching and positive-true versus negative-true matches. The implementation above enforces the use of exactly and only de.example.com and www.example.com -- any other variations of domain, subdomain, casing, FQDN-format, or appended port numbers will be redirected to one of those two canonical hostnames.

Mind also the character-escaping rule differences between exact-text matches using the "=" operator, and regular-expressions matching (which is the default mode, but slower).

The above six rules work together as a complete system, and are not separable without modification. Their advantages are complete hostname canonicalization, resolution of the language-folder-versus-language-subdomain ambiguity, and elimination of the requirement to expose the server-internal file structure used to support multiple languages -- and this also makes the URLs shorter. :)

However, I should emphasize that your on-page links must be corrected to remove the language-folder path-parts, linking instead only to the correct language-specific subdomains. Do not rely on the first two redirects in this code to 'fix' these links, because the result will be one redirect for every page loaded, slowing down your server and your users, and making a mess of your log files and the "statistics" derived from those logs.

Jim

guum

8:42 pm on May 7, 2010 (gmt 0)

10+ Year Member



Thank you for your efforts jdMorgan

-------------
There is no need to 'expose' either the 'en-folder' or the 'de-folder' *filepath* in the URL. It is wasted bytes.
Instead, remove "en-folder/" and "de-folder/" from your on-page links, use only the "www" and "de" subdomains in on-page links which are used to change between languages, and try something like this:

------------

it's hard to imagine how the problem really looks like...

everything works fine, but there is a possibility in the English area: to view the German side.
Background: Both languages were originally together on the example.com. But Google refused my English content and and keep only the German (?). I decided then to separate the two languages. And then the problems started. In the beginning, I have a folder for each domain or subdomain. redirect was not necessary because I've customized the site, but I wanted to prevent the just described possibility.

I have so redirected:

RedirectMatch 301 ^/cad-verzeichnis/(.*)$ http:://de.example.com/cad-verzeichnis/$1
(.htaccess from 'de.example.com' root folder)

RedirectMatch 301 ^/cad-directory/(.*)$ http:://www.example.com/cad-directory/$1
(.htaccess from 'www.example.com' root folder)

Synchronize the two folders was hard, then I have set only one folder for domain and subdomain,
and now redirectmach work no longer .
-----------
Your example:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /de-folder/[^\ ]*\ HTTP
RewriteRule ^de-folder/(.*)$ http:://de.example.com/$1 [R=301,L]
don't work.




I have a lot of rules in the. htaccess file, but here to test the most important rules that can not be removed.
---------------------------------------
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR]
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php


#############################################################
### http:://example.com -> redirects to http:://www.example.com
### http:://www.example.com -> does not redirect
### http:://subdomain.example.com -> does not redirect
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#############################################################


# nothing happens
# does not work: but that is what I want and with this is sufficient:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-verzeichnis/[^\ ]*\ HTTP
RewriteRule ^/cad-verzeichnis/(.*)$ http:://de.example.com/cad-verzeichnis/$1

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-directory/[^\ ]*\ HTTP
RewriteRule ^cad-directory/(.*)$ http:://www.example.com/$1 [R=301,L]


# does not work: also example for individual pages
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-community-en.html
RewriteRule ^cad-community-en.html http:://de.example.com/cad-community-en.html

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-community-de.html
RewriteRule ^cad-community-de.html http:://www.example.com/cad-community-de.html
---------------------------------------

I think it needs to be checked first if

http:://www.example.com/
or
http:://de.example.com/

because the rules can be read from domain and subdomain

Idea:
RewriteCond... check whether subdomain 'de' or subdomain 'www'
then rule.


Thanks for any ideas

[edited by: jdMorgan at 2:50 am (utc) on May 8, 2010]
[edit reason] Please use example.com only. [/edit]

g1smd

9:09 pm on May 7, 2010 (gmt 0)

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



You have major problems here.

Make sure that all of your redirects and all of your rewrites use RewriteRule code.

Absolutely do not mix Redirect and RedirectMatch directives here. Use ONLY RewriteRule.

Add the [L] flag to every RewriteRule directive.

Order the rules from most specific first (those affecting a single or small number of URLs) to least specific last (i.e. the canonical non-www to www redirect).

List all redirects before any of the rewrites are listed. You have the rewrite listed first. It must be moved to be after the redirects.

guum

1:05 pm on May 9, 2010 (gmt 0)

10+ Year Member



there are some mistakes:
---------------------------------------
# nothing happens
# does not work: but that is what I want and with this is sufficient:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-verzeichnis/[^\ ]*\ HTTP
RewriteRule ^cad-verzeichnis/(.*)$ http:://de.example.com/cad-verzeichnis/$1

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-directory/[^\ ]*\ HTTP
RewriteRule ^cad-directory/(.*)$ http:://www.example.com/cad-directory/$1 [R=301,L]


# does not work: also example for individual pages
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-community-en.html
RewriteRule ^cad-community-en.html http:://www.example.com/cad-community-en.html

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cad-community-de.html
RewriteRule ^cad-community-de.html http:://de.example.com/cad-community-de.html
---------------------------------------

guum

3:27 pm on May 16, 2010 (gmt 0)

10+ Year Member



I'm still here ;-)

This code works, it is detected where I am: domain or subdomain,
but index.php is there wrong. Can anyone recognize the problem and help me?

Thanks in advance


------------------

RewriteCond %{HTTP_HOST} www.example.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/(.*)$
RewriteRule ^(.*)$ http:://de.example.com/cad-verzeichnis/$1 [L,R=301]

I want:
http:://www.example.com/cad-verzeichnis/
to
http:://de.example.com/cad-verzeichnis/

redirect but wrong:
http:://de.example.com/cad-verzeichnis/index.php/

---

I want:
http:://www.example.com/cad-verzeichnis/cad-maschinenbau-anlagenbau.html
to
http:://de.example.com/cad-verzeichnis/cad-maschinenbau-anlagenbau.html

redirect but wrong:
http:://de.example.com/cad-verzeichnis/index.php/cad-maschinenbau-anlagenbau.html

-------------

RewriteCond %{HTTP_HOST} de.example.com
RewriteCond %{REQUEST_URI} ^/cad-directory/(.*)$
RewriteRule ^(.*)$ http:://www.example.com/cad-directory/$1 [L,R=301]


I want:
http:://de.example.com/cad-directory/
to
http:://www.example.com/cad-directory/

redirect but wrong:
http:://www.example.com/cad-directory/index.php/

---

I want:
http:://de.example.com/cad-directory/cad-mechanical.html
to
http:://www.example.com/cad-directory/cad-mechanical.html

redirect but wrong:
http:://www.example.com/cad-directory/index.php/cad-mechanical.html

-------------

jdMorgan

5:42 pm on May 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Heed the details, every one.

Posted above:
Add the [L] flag to every RewriteRule directive.


Jim

guum

8:13 pm on May 24, 2010 (gmt 0)

10+ Year Member



Thank you g1smd and jdMorgan !

Order the rules from most specific first (those affecting a single or small number of URLs) to least specific last (i.e. the canonical non-www to www redirect).

List all redirects before any of the rewrites are listed. You have the rewrite listed first. It must be moved to be after the redirects.

Absolutely do not mix Redirect and RedirectMatch directives here. Use ONLY RewriteRule.

Heed the details, every one.

Add the [L] flag to every RewriteRule directive.
[L,R=301] work too.


This code works:

----------------------------
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# now and not later (1)

RewriteCond %{HTTP_HOST} www.example.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/(.*)$
RewriteRule ^(.*)$ http:://de.example.com/$1 [L]

RewriteCond %{HTTP_HOST} de.example.com
RewriteCond %{REQUEST_URI} ^/cad-directory/(.*)$
RewriteRule ^(.*)$ http:://www.example.com/$1 [L]

#

RewriteCond %{HTTP_HOST} www.example.com
RewriteCond %{REQUEST_URI} ^/sitemap-de.html
RewriteRule ^(.*)$ http:://de.example.com/sitemap-de.html [L]

RewriteCond %{HTTP_HOST} de.example.com
RewriteCond %{REQUEST_URI} ^/sitemap-en.html
RewriteRule ^(.*)$ http:://www.example.com/sitemap-en.html [L]

# ........ (2)

### http:://example.com -> redirects to http://www.example.com
### http:://www.example.com -> does not redirect
### http:://subdomain.example.com -> does not redirect
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ........ (3)

# ...... redirect works fine too
RedirectMatch 301 ^/frontpage/(.*)$ /
RedirectMatch 301 ^/frontseite/(.*)$ /

# ............

g1smd

9:00 pm on May 24, 2010 (gmt 0)

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



You still need to fix all of these issues:

Make sure that all of your redirects and all of your rewrites use RewriteRule code.

Absolutely do not mix Redirect and RedirectMatch directives here. Use ONLY RewriteRule.

Order the rules from most specific first (those affecting a single or small number of URLs) to least specific last (i.e. the canonical non-www to www redirect).

List all redirects before any of the rewrites are listed.

Redirects need [R=301,L] otherwise they deliver a 302 redirect. Rewrites need the [L] flag.

jdMorgan

2:21 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you mix mod_alias directives like Redirect Match with mod_rewrite directives like RewriteRule, you have no way to know which module will execute first, and therefore you have no way to know which directives will be executed first. Directive processing is per-mdule, and not strivtly in the order the directives are written in the .htaccess file.

If you put internal rewrites ahead of external redirects, then if an internal rewrite executes first, followed by an external redirect execution, the redirect will expose the internally-rewritten filepath as a URL to the client, and you end up with the kind of problem described here -- the "language" subfolders appearing as URLs and getting listed in search engines.

If you put less-specific rules first, then it is likely that a less-specific rule will match a requested URL and redirect it or rewrite it before a rule intended for only that URL can execute. This leads to 'weird' operation of your site at best, or a broken site at worst.

mod_rewrite execution in .htaccess is recursive. If a mod_rewrite rule is invoked, then mod_rewrite procesing is re-started from the top. This continues until a pass is made through all rules without any rule being invoked. For this reason, and for the reasons listed above, it is important to use the [L] flag on every rule for best efficiency.

Hopefully these details will help to overcome the language barrier. All of the advice you find posted in this forum is correct. While we may miss a few posts, any incorrect information or advice is usually corrected quickly, either by the members or by the moderators. Therefore, if someone tells you not to mix RewriteRule and RedirectMatch, you will find that if you do mix them you will very likely have big trouble -- now or later (say, after a server upgrade).

-----

Some clean-ups are needed. All literal periods in regular-expressions patterns should be escaped, and there is not need to specify a leading or trailing ".*" pattern unless the string matching that pattern needs to be captured and re-used (back-referenced). Patterns should be fully-anchored when possible to improve efficency, except in these cases where it would require a leading or trailing ".*" subpattern.

So taking just the first rule in the previous code post:

RewriteCond %{HTTP_HOST} www.example.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/(.*)$
RewriteRule ^(.*)$ http:://de.example.com/$1 [L]

it can be improved to

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/
RewriteRule ^(.*)$ http:://de.example.com/$1 [L]

which should be entirely equivalent, but faster.

Jim

guum

4:20 pm on Jun 20, 2010 (gmt 0)

10+ Year Member



Hello. Here am again (after holiday)

Thank you djMorgan and g1smd!

Everything works now well. I have x bloks with rules,
this is my oder:

-------------------

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

### 1

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-uebersicht.html
RewriteRule ^(.*)$ http:://de.example.com/cad-uebersicht.html [R=301,L]

RewriteCond %{HTTP_HOST} ^de\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-overview.html
RewriteRule ^(.*)$ http:://www.example.com/cad-overview.html [R=301,L]

...............

### 2

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/
RewriteRule ^(.*)$ http:://de.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^de\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-directory/
RewriteRule ^(.*)$ http:://www.example.com/$1 [R=301,L]

...................

But how to change these redirects?

redirectMatch 301 home.html /


I want:
http:://www.example.com/home.html
alway to
http:://www.example.com/


Thanks again, that was a good idea to ask my question here ...

jdMorgan

4:54 pm on Jun 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RedirectMatch 301 home.html /

becomes

RewriteRule ^home\.html$ http://www.example.com/ [R=301,L]

However, do you see the problem? With either the old or the new redirect, the target hostname is always "www.example.com" -- Even if de.example.com/home.html is requested, the redirect is always to www.example.com/
And that may not be what you want.

So, perhaps

RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http://%1example.com/ [R=301,L]

In this way, requests for www.example.com/home.html or example.com/home.html are redirected to www.example.com/ and requests for de.example.com/home.html are redirected to de.example.com/

However, there may still be a problem if "home.html" is defined as your 'index pages' in a DirectoryIndex directive -- either in your .htaccess file or in a server config file. If that is the case, then you will need to add another rewritecond in order to stop an "infinite" redirect/rewrite loop:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /home\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http://%1example.com/ [R=301,L]

But there's still another problem: "/home.html" will be redirected to "/" only if the request is for the root directory. If you also have requests for /subdirectory/home.html, then that subdirectory-path will be lost. So the cure for that is

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*home\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^(([^/]+/)*)home\.html$ http://%1example.com/$1 [R=301,L]

Lots and lots of 'little details' in this stuff... :)

Jim

guum

6:49 pm on Jun 27, 2010 (gmt 0)

10+ Year Member



This is my fault: i should explain this problem more exactly:

redirectMatch 301 home.html /

I want:
http:://www.example.com/home.html
OR
http:://de.example.com/home.html
alway to
http:://www.example.com/
----
redirectMatch 301 startseite.html /

I want:
http:://www.example.com/startseite.html
OR
http:://de.example.com/startseite.html
alway to
http:://de.example.com/

----------------------------
Your next code does perfectly... ;-)

######################################
RewriteRule ^home\.html$ http:://www.example.com/ [R=301,L]
RewriteRule ^startseite\.html$ http:://de.example.com/ [R=301,L]
######################################

But what is with your another code:

RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http:://%example.com/ [R=301,L]

request
http:://www.example.com/
answer
http:://www.%example.com/

request
http:://de.example.com/
answer
http:://www.%example.com/

------------------------

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /home\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http:://%example.com/ [R=301,L]

request
http:://www.example.com/
answer
http:://www.%example.com/

request
http:://de.example.com/
answer
http:://www.%example.com/

------------------------

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*example\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^(([^/]+/)*)suche\.html$ http:://%example.com/$1 [R=301,L]

request
http:://de.example.com/cad-markt/suche.html
answer
http:://de.example.com/cad-markt/suche.html

request
http:://www.example.com/cad-markt/suche.html
answer
http:://de.example.com/cad-markt/suche.html

--------------------------------------------------
I still have some redirects. Not so important because only for a short time.

redirectMatch 301 ^/cax-directory/(.*)$ /cad-directory/$1
redirectMatch 301 cad-verzeichnis/3ds-max.html http:://www.cadenigma.com/cad-directory/3ds-max.html



Sorry, so many questions, but .htaccess professionals can not be found so easy...

jdMorgan

7:44 pm on Jun 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But what is with your another code:

RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http:://%example.com/ [R=301,L]


You omitted the "1" -- It is quite important...

RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http:://%1example.com/ [R=301,L]

Jim

guum

11:21 am on Jun 28, 2010 (gmt 0)

10+ Year Member



I thought it's a typo...........

I have tried everything.
Here are the results:
-------------------------


RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http:://%1example.com/ [R=301,L]

request
http:://example.com/home.html
http:://www.example.com/home.html
answer
http:://www.example.com/

request
http:://de.example.com/home.html
answer
http:://de.example.com/

However, there may still be a problem if "home.html" is defined as your 'index pages' in a DirectoryIndex directive -- either in your .htaccess file or in a server config file. If that is the case, then you will need to add another rewritecond in order to stop an "infinite" redirect/rewrite loop:


Duplicate content in my case, with this rule I want "home.html" defined as 'index pages'.

--------------------------------------------------------------

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /home\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^home\.html$ http:://%1example.com/ [R=301,L]

request
http:://example.com/home.html
http:://www.example.com/home.html
answer
http:://www.example.com/

request
http:://de.example.com/home.html
answer
http:://de.example.com/

--- same like above, for subdirectory----

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /suche\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^suche\.html$ http:://%1example.com/ [R=301,L]

request
http:://de.example.com/cad-markt/suche.html
answer
http:://de.example.com/cad-markt/suche.html

request
http:://www.example.com/cad-markt/suche.html
answer
http:://www.example.com/cad-markt/suche.html

request
http:://example.com/cad-markt/suche.html
answer
http:://example.com/cad-markt/suche.html

----------------------------------------------------------------

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*home\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^(([^/]+/)*)home\.html$ http:://%1example.com/$1 [R=301,L]

request
http:://example.com/home.html
http://www.example.com/home.html
answer
http:://www.example.com/

request
http:://de.example.com/home.html
answer
http:://de.example.com/


--- same like above, for subdirectory----


RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*suche\.html([?#][^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} ^((www|de)\.)example\.com [NC,OR]
RewriteCond www.%{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^(([^/]+/)*)suche\.html$ http:://%1example.com/$1 [R=301,L]

request
http:://www.example.com/cad-markt/suche.html
answer
http:://www.example.com/cad-markt/

request
http:://example.com/cad-markt/suche.html
answer
http:://www.example.com/cad-markt/

request
http:://de.example.com/cad-markt/suche.html
answer
http:://de.example.com/cad-markt/


-----------------------------------------------

If anyone needs ideas from results, he will ask.
I have everything written down as example,
for me, you do not invest more time.

Thanks again!

###############################
Are these questions too much?


redirectMatch 301 ^/cax-directory/(.*)$ /cad-directory/$1
redirectMatch 301 cad-verzeichnis/3ds-max.html http:://www.cadenigma.com/cad-directory/3ds-max.html

g1smd

12:46 pm on Jun 28, 2010 (gmt 0)

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



Why are you still posting RedirectMatch snippets?

Absolutely do NOT use any Redirect or RedirectMatch directives.

Use RewriteRule for all.

I would be able to better follow what you want to do, if each block of code was concisely
# commented
as to exactly what it is supposed to do.

As for your "request" and "answer" data; is that what you want it to do (but it does something else), or what it actually does (but you want something different)?

guum

2:19 pm on Jun 28, 2010 (gmt 0)

10+ Year Member



The story is simple: since about three months I have a shared root folder,
but before, for each domain and subdomain: one folder.
My .htaccess was full of redirectmach, and I want everything to change in RewriteRule.

My second last question was:
how do I change these redirectMatch?

redirectMatch 301 home.html /
redirectMatch 301 startseite.html /


I want:
http:://www.example.com/home.html
OR
http:://de.example.com/home.html
alway to
http:://www.example.com/
----

I want:
http:://www.example.com/startseite.html
OR
http:://de.example.com/startseite.html
alway to
http:://de.example.com/



and this works perfectly for me! Thanks.

---------------------------------------------------------------
RewriteRule ^home\.html$ http:://www.example.com/ [R=301,L]
RewriteRule ^startseite\.html$ http:://de.example.com/ [R=301,L]
---------------------------------------------------------------


The rest I have tested, because djMorgan has made some effort.


I am working as cad designer, and I build this Website (cadenigma.com).
with no Web experience...

I think I have you enough engaged.

Konstantin

Thanks and Sorry for my bad English.