Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
March 12, 2010, 09:27:52 AM

Pages: [1]   Go Down
  Print  
Author Topic: canonical hostnames www.mydomain.com by rewrite rules in .htaccess  (Read 796 times)
oleh
Newbie
*
Offline Offline

Posts: 2


« on: February 28, 2009, 12:04:27 PM »

Hello everybody,

so this sounds pretty easy and basic. Following the advice in http://httpd.apache.org/docs/1.3/misc/rewriteguide.html this was entered in the root .htaccess file:

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST}   !^www\.mydomain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http:\/\/www\.mydomain\.com/$1 [L,R]

But it doesn't work. Loading a page with or without the "www." prefix by typing in browser address bar works fine, so both variants are supported by the web server (Apache 1.3.41).

Checking the host name with request.getServerName() in a .jsp file served by Resin 3.1.8 shows "mydomain.com" in both variants, i.e. also when the page is loaded with the "www." prefix.

Any hint in the right direction is highly appreciated!  Help
Logged
tgibbons
Spaceship Captain
*****
Offline Offline

Posts: 112


« Reply #1 on: February 28, 2009, 07:38:41 PM »

So, do you want mydomain.com to redirect to www.mydomain.com? Try:

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]
Logged

Tom
oleh
Newbie
*
Offline Offline

Posts: 2


« Reply #2 on: March 01, 2009, 06:23:55 AM »

Awesome - that did the trick!  Bouncin for Joy (Removed the NC from the rule since it seemed not necessary.)

Thank you so much!
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: