Development Mod Rewrite help

Discussion in 'Software' started by Shuriken, 30 Dec 2008.

  1. Shuriken

    Shuriken same christmas AV for a whole year

    Joined:
    1 Jan 2003
    Posts:
    1,312
    Likes Received:
    22
    Hi all,

    I could do with some help with mod rewrite. The situation is this:

    I have a domain (for the client's privacy we'll call it www.example.co.uk) with an SSL certificate. The certificate only works with out the www. prefix, as as the client doesn't want to shell out for another IP address and certificate for the www. version. (In hind sight I should have set the certificate up for the www. url)

    I've got mod rewrite redirecting any non-https requests to the https site like this:

    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://example.co.uk/
    but if someone specifically goes to https://www.example.co.uk they get the old dodgey certificate warning.

    Does anyone know how I can also make it redirect https://www.example.co.uk to https://example.co.uk?

    Cheers
     
  2. Shuriken

    Shuriken same christmas AV for a whole year

    Joined:
    1 Jan 2003
    Posts:
    1,312
    Likes Received:
    22
    I've figured it out, just had to use the HTTP_HOST variable and check for www.

    Code:
    rewriteCond %{HTTP_HOST} ^(www\.)example\.co\.uk [NC]
    RewriteRule (.*) http://example.co.uk/
    Thought I'd post the solution in case anyone else ever has this problem
     
    RTT likes this.

Share This Page