Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6471153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:11:30+00:00 2026-05-25T06:11:30+00:00

I’m flabbergasted! I’ve been trying for hours to redirect, via .htaccess, two specific pages

  • 0

I’m flabbergasted! I’ve been trying for hours to redirect, via .htaccess, two specific pages to HTTPS, and force all other pages to always use HTTP. One of the URLs is dynamic, and that’s where my problem lies. No example I’ve found has worked for me. Below is my present code. I finally did get the turning on part to work, so it’s just turning off SSL I need help with. The only pages that should use SSL are login.php and register.php?country=xx where xx varies and is always lower-case letters.

Options +FollowSymLinks
RewriteEngine on

# Turn on ssl for specific pages
RewriteCond %{HTTPS} off
RewriteRule ^login\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} ^country=([a-z]+)$
RewriteRule ^register.php https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Turn off ssl when not accessing specific pages
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/register.php\?country=([a-z]+)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !\/login.php$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Redirect non-canonical hostname requests, preserving http/https
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^(.*)$ http%2://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:11:30+00:00Added an answer on May 25, 2026 at 6:11 am

    You do not really need to check what country=xx is — it’s a query string parameter and is not important. Redirect to HTTPS should occur on per page basis, not per query string parameter.

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /
    
    # force https for /login.php and /register.php
    RewriteCond %{HTTPS} =off
    RewriteRule ^(login|register)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    # don't do anything for images/css/js (leave protocol as is)
    RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]
    
    # force http for all other URLs
    RewriteCond %{HTTPS} =on
    RewriteCond %{REQUEST_URI} !^/(login|register)\.php$
    RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    # your other rewrite rules below
    
    1. These rules need to be placed in .htaccess in website root folder BEFORE any other rewrite rules (if such present). If placed elsewhere some small tweaking may be required.

    2. They will

      • force HTTPS for /login.php and /register.php,
      • do nothing for images, css styles and JavaScript files (to be precise, for files with those extensions)
      • and will force HTTP for all other URLs
    3. You can easily add other URLs to that list — just edit existing rule by adding additional file name to the list (the same text in 2 places: 1) to force 2) to exclude)

    4. File names are case-sensitive. So these rules will not work if /LOGIN.php is requested (Apache will not serve it either, as Linux is case-sensitive OS .. so no need to worry much here).

    5. Obvious thing: mod_rewrite should be enabled and .htaccess files needs to be processed by Apache (some website hosting companies disabling them for performance and security reasons).

    IMPORTANT NOTE:
    It is very likely that these rule will not work for you straight away. That is because modern browser do CACHE 301 redirects from your previous attempts. Therefore I recommend testing it on another browser and change 301 to 302 during testing (302 is not cached) .. or clear all browser caches (maybe even history) and restart browser.


    BTW:

    1. No need to escape slash in %{SCRIPT_FILENAME} !\/login.php$

    2. %{SCRIPT_FILENAME} will only match file name and definitely not the query string, therefore !\/register.php\?country=([a-z]+)$ make no sense at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.