Forum Moderators: phranque
[edited by: jdMorgan at 4:57 pm (utc) on Jun 20, 2010]
[edit reason] De-linked [/edit]
# 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]
[edited by: jdMorgan at 2:50 am (utc) on May 8, 2010]
[edit reason] Please use example.com only. [/edit]
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.
RewriteCond %{HTTP_HOST} www.example.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/(.*)$
RewriteRule ^(.*)$ http:://de.example.com/$1 [L]
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/
RewriteRule ^(.*)$ http:://de.example.com/$1 [L]
RedirectMatch 301 home.html /
RewriteRule ^home\.html$ http://www.example.com/ [R=301,L]
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]
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]
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]
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]
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]
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:
# commented as to exactly what it is supposed to do.