Troubles enforcing canonical hostname in a .htaccess file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux