SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    htaccess force ssl for a particlular domain

    Hello forums,

    How do I force SSL for a particular domain currently I have

    Code HTML4Strict:
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    This is working, however I have several add on domains on my hosting and when I try to access the other add-on domains, the add on domains are also forced to use SSL .

    I tried this:

    Code HTML4Strict:
    RewriteCond %{HTTP_HOST} ^mydomain\.org$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.mydomain\.org$
    RewriteRule ^/?$ "https\:\/\/www\.mydomain\.org\/" [R=301,L]

    But it is giving me an infinite loop.

    Thanks.
    Don't Panic

  2. #2
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} exampledomain\.org$ [NC]
    RewriteRule ^ https://www.examplemydomain.org%{REQUEST_URI} [R=301,L,NE]
    Don't Panic

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    sd,

    That's pretty close ( ) but I believe that {HTTPS} can only be null or "on" (without the quotes) so I check for not port 443 (SSL off). Your second line is SPOT ON! Your third, though, bothers me as the regex is simply the start anchor then the redirection - I'd recommend ".?" (without the quotes) as it will forct the match you're looking for.

    Is there a reason you're using the No Escape flag? IMHO, that's not needed.

    To summarize, my code looks like:

    Code:
    RewriteCond %{SERVER_PORT} !^443$
    RewriteCond %{HTTP_HOST} exampledomain\.org$ [NC]
    RewriteRule .? https://www.examplemydomain.org%{REQUEST_URI} [R=301,L]
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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