Forum Moderators: phranque
I've got the following mod_rewrite to redirect to different "virtual subfolders" depending on your language:
RewriteEngine onRewriteRule ^(de¦en)$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
RewriteRule ^(de¦en)/(index\.php)?$ index.php?language=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(de¦en)/(.*)$ $2?language=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(de¦en)/(.*)$ $2 [L]
RewriteCond %{HTTP_HOST} !^www\.[^.:]+\.(co\.[a-z]{2}¦[a-z]{2,6})\.?(:[0-9]+)?$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
Now I want to redirect directly to the Domain itself and not anymore to the www.DOMAIN.
So I tried to change the code as follows:
RewriteEngine on#Remove the "www." in the first RewriteRule
#Externally redirect; Add "www"
RewriteRule ^(de¦en)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteRule ^(de¦en)/(index\.php)?$ index.php?language=$1 [QSA,L]
# Rewrite all URL-paths in en/ and de/ subdirectories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(de¦en)/(.*)$ $2?language=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(de¦en)/(.*)$ $2 [L]
#What should I do here?
# Externally redirect to add "www" and remove trailing periods
# and/or port numbers on requested non-www hostnames
RewriteCond %{HTTP_HOST} !^www\.[^.:]+\.(co\.[a-z]{2}¦[a-z]{2,6})\.?(:[0-9]+)?$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
I am looking forward to your ideas!
Michael
Your rule changes do not reflect your stated goal. Working from the code in your original post, you'd need:
RewriteEngine on
#
# Externally redirect requests for non-canonical "www" subdomain to non-www domain
RewriteCond %{HTTP_HOST} ^www\.([^.:]+\.(co\.[a-z]{2}¦[a-z]{2,6}))\.?(:[0-9]+)?$
RewriteRule (.*) http://%1/$1/ [R=301,L]
#
# Internally rewrite URL-path requests for /<language>/ or /<language>/index.php
# to script filepath /index.php?language=<language>
RewriteRule ^(de¦en)/(index\.php)?$ index.php?language=$1 [QSA,L]
#
# If requested URL-path /<language>/<anything> does NOT resolve to an existing directory,
# internally rewrite those requests to the filepath /<anything>?language=<language>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(de¦en)/(.*)$ $2?language=$1 [QSA,L]
#
# If requested URL-path /<language>/<anything> does NOT resolve to an existing
# file, internally rewrite those requests to the filepath /<anything>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(de¦en)/(.*)$ $2 [L]
Jim
I had uploaded the file via ftp an visited my homepage to check the script.
Unfortunately I wasn't able to visit more than one page of my website, because the Apache needed all the system memory at once for this request.
I removed the htaccess from my server, but I couldn't visit any site of my website.
The only resoluten was to restart Apache, and then it worked.
I don't know what is wrong, but I know, that this is a bug off course.
But I don't know if the script is wrong or my apache ;)
Michael
[edited by: Fireball22 at 11:29 pm (utc) on Feb. 14, 2009]