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 6143139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:29:01+00:00 2026-05-23T18:29:01+00:00

Struggling with mod_rewrite trying to redirect a non-secure page to a secure one. This

  • 0

Struggling with mod_rewrite trying to redirect a non-secure page to a secure one. This works:

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} (help/returns) 
RewriteRule .? https://mysite.localhost/%1/ [R=301,L]

But this doesn’t:

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{HTTP:Host} (mysite.localhost|mylivesite.com)
RewriteCond %{REQUEST_URI} (help/returns) 
RewriteRule .? https://%1/%2/ [R=301,L]

The URL it tries to give me is https://help/returns//

I can’t seem to get the HTTP:host into the final RewriteRule line.

I need the host in there so I can use the same file for local dev and live deployment.

Most grateful for any input.

  • 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-23T18:29:01+00:00Added an answer on May 23, 2026 at 6:29 pm

    You can use this rule:

    RewriteCond %{HTTPS} =off
    RewriteRule ^help/returns https://%{HTTP_HOST}%{REQUEST_URI} [QSA,R=301,L]
    
    1. This rule will redirect all requests to http://example.com/help/returns to a secure (HTTPS) location: https://example.com/help/returns — it will preserve full URL path + query string. You have too many conditions, rule becomes complex which is not a good thing when your server is REALLY busy (regular expressions are expensive).

    2. I have replaced %{SERVER_PORT} 80 by more proper %{HTTPS} =off (this especially useful if your site is run on non-default port, which is 80).

    3. I have also removed HTTP_HOST matching part — you don’t really need it unless you have more than one domain name/subdomain bound to the same site. In case if you need this condition just add this line after 1st line: RewriteCond %{HTTP_HOST} ^(mysite.localhost|mylivesite.com)

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

Sidebar

Related Questions

Really struggling to figure this out. Just trying to take in data from php
Struggling with this one. I have set up a basic email/enquiry form for a
really struggling to resolve this issue. using nhibernate Im trying to join two different
really struggling with this one. I've recently setup a bash shell script to extract,
Really struggling with this one: I have an existing foreach, containing an if loop
Im struggling to find an answer for this one. I've found out how to
I'm struggling with probably quite simple mod_rewrite taks. This is the directory structure I
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising
Im struggling here for a lot, Im trying to upload an image from iphone

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.