Results 1 to 7 of 7

Thread: .htaccess Question

  1. #1
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    227
    Thanks
    82
    Thanked 3 Times in 3 Posts

    Default .htaccess Question

    I suppose technically this is more Apache than html, but Dynamic Drive has no Apache forum, and html seems a bit more descriptive than "other," so I hope y'all will indulge me:

    My .htaccess file begins with the following:

    Code:
    ErrorDocument 404 /404.html
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^marainlaw\.com
    RewriteRule ^(.*)$ https://www.marainlaw.com/$1 [R=301,L]
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
    Might someone be able to indicate exactly what the "RewriteRule ^(.*)$ https://www.marainlaw.com/$1 [R=301,L]" statement does, and what would be the effect of its removal?

    A.

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,875
    Thanks
    49
    Thanked 263 Times in 255 Posts
    Blog Entries
    56

    Default

    See this.
    You could also use javascript to redirect the visitor to https:// by doing something like
    Code:
    /*HTTP to HTTPS redirect for a site having 'yoursite.com' as its domain name*/
    /*Put this on all pages of yoursite:*/
    var my_domain='yoursite.com'
    if (location.protocol == 'http:' && document.URL.substring(document.URL.indexOf(my_domain), document.URL.length).substring(0, my_domain.length) == my_domain) {location.href = location.href.replace(/^http:/, 'https:')}

  3. #3
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    227
    Thanks
    82
    Thanked 3 Times in 3 Posts

    Default

    RewriteRule ^(.*)$ https://www.marainlaw.com/$1 [R=301,L] was in my .htaccess file. It was forcing all visits to http pages to instead seek an https page, including for subdomains. That is good--I wanted that. NOW, however, I have an additional subdomain that I want excluded from that force. Let's call it xyz subdomain. I am looking for an .htaccess modification that can keep the forced http ---> https for all domains and subdomains except for this xyz subdomain, which should remain http.

  4. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,875
    Thanks
    49
    Thanked 263 Times in 255 Posts
    Blog Entries
    56

    Default

    Remove the RewriteRule from the .htaccess file , then put
    Code:
    <script>
    var my_domain='marainlaw.com'
    if (location.protocol == 'http:' && document.URL.substring(document.URL.indexOf(my_domain), document.URL.length).substring(0, my_domain.length) == my_domain) {location.href = location.href.replace(/^http:/, 'https:')}
    </script>
    in all pages where you want to redirect your visitors to https://. So you should not put the script in the pages of the xyz subdomain.

  5. The Following User Says Thank You to molendijk For This Useful Post:

    marain (09-24-2019)

  6. #5
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    227
    Thanks
    82
    Thanked 3 Times in 3 Posts

    Default

    Molendijk,

    First of all, thank you!

    Your facility with javascript is two or three orders of magnitude greater than mine. I vaguely follow what you suggest, and assume your solution will work. But (ungrateful wretch that I am), I was hoping for something (a line or two perhaps in .htaccess?) just a bit more elegant.

    Regardless, you focused hard on my question, and deserve a thanks. Here it is!

    Best,

    A.

  7. #6
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,875
    Thanks
    49
    Thanked 263 Times in 255 Posts
    Blog Entries
    56

    Default

    Marain, thanks.
    For now, I'm unsure about how to do it inside the .htaccess file, sorry. Perhaps someone else?
    I have a site with a subdomain for one of my children who doesn't want an SSL certificate. So I put the required javascript lines inside my own pages only. It works.

  8. #7
    Join Date
    Oct 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    According to new google algorithm rules you should redirect all links to https with a secure SSL certificate.

Similar Threads

  1. Resolved htaccess question
    By james438 in forum PHP
    Replies: 4
    Last Post: 03-06-2010, 11:24 PM
  2. HTACCESS Question About Restricting Access
    By smitsmah in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-13-2009, 02:21 PM
  3. .htaccess file question
    By SolitudeDude in forum Other
    Replies: 4
    Last Post: 11-12-2008, 01:40 PM
  4. .htaccess and mysql question
    By benslayton in forum PHP
    Replies: 1
    Last Post: 03-27-2008, 02:51 AM
  5. .htaccess login question
    By PudgiPod in forum Other
    Replies: 2
    Last Post: 03-13-2007, 01:43 AM

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
  •