SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: HTTPS redirect

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTTPS redirect

    I'm trying to force https on an admin area of a site, my current htaccess file looks like this:

    RewriteCond %{HTTPS} !=on
    RewriteCond %{REQUEST_URI} admin
    RedirectPermanent ^(.*)$ https://www.example.com/admin/$1 [R=301,NC,L]

    but this puts it into a loop and I end up with something like

    https://www.example.com/admin/admin/...dmin/admin/etc...

    thanks in advance

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

    {HTTPS} will be null and not really available to test if the request is not in https protocol. That's why I recommend (and use) {SERVER_PORT} (80 for http, 443 for https) as shown in my signature's tutorial.

    Further, admin could be anywhere in your mod_rewrite so that's probably not acceptable as a condition.

    Finally, Attaching a RedirectPermanent to a RewriteCond won't work as mod_alias take precedence over mod_rewrite (and works separately).

    Give this a try:
    Code:
    RewriteCond %{SERVER_PORT} ^80$
    RewriteCond %{REQUEST_URI} 
    RewriteRule ^admin/(.*)$ https://www.example.com/admin/$1 [R=301,QSA,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
  •