httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olivier Sannier <obo...@free.fr>
Subject [users@httpd] Troubles enforcing canonical hostname in a .htaccess file
Date Tue, 30 Dec 2008 15:30:01 GMT
Hi all,

I have a website with an associated domain name hosted by a third party 
provider.
They let me place .htacess files in folders and mod_rewrite is enabled.
I would like that any request for "mydomain.com" be redirected to 
"www.mydomain.com" while letting through any request for other third 
level domains (such as test.mydomain.com or static.mydomain.com)
For the CMS that is handling the web content, I already have a 
RewriteRule that redirects any non existent folder or file to index.php, 
declared like this :

-------------------------------------------------------------------------------
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [L,NC]
-------------------------------------------------------------------------------

I looked around and saw the example about canonical hostnames indicated 
inside the mod_rewrite guide here:
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html#url

So I tried to adapt the given example and modified my .htacess file to this:

-------------------------------------------------------------------------------
RewriteEngine On

RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^/(.*)$  http://www.mydomain.com/$1 [L,R=301]

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [L,NC]
-------------------------------------------------------------------------------

Unfortunately, this does not seem to work, requests made to 
http://domain.com/ are not redirected to http://www.mydomain.com/ but 
served directly by index.php, it's as if the first rule is not used at all.
I must be missing something obvious here, but I can't figure it right now.

Any help will be very much appreciated.

Regards
Olivier

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message