Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    stripping www from URL with .htaccess

    I would like to redirect all users to https. This works fine with this code.

    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    # redirect if it looks like this https://domain.com/svrduzx8xCupDgJHpOdq 
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.* - [L]
    RewriteBase /
    RewriteRule ^([a-zA-Z0-9]+)$ https://%{HTTP_HOST}/application.php?i=$1
    But the problem is that some users still type www, resulting in https://www.domain.com. This gives a ssl cert error.
    So I would like to first strip the www before redirecting to https. I've tried different approaches, such as:

    Code:
    # remove www from host
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
    But I can't get it to work. .htaccess is pretty new to me, anyone with experience who knows how to get this done (properly)?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try
    Code:
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks abduraooft for your reply!
    Your code works, but only for www.domain.com

    It won't redirect https://www.domain.com
    Any idea how to tackle this?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •