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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:23:08+00:00 2026-05-28T06:23:08+00:00

I have the following code for my .htaccess file that I’ve picked up from

  • 0

I have the following code for my .htaccess file that I’ve picked up from here and tried adapting it as I understand from .htaccess, yet I can’t seem to get it to work (or maybe the browser has cached it but I can’t seem to clear it).

Options -Indexes
Options +FollowSymlinks

<IfModule mod_rewrite.c>

########## FORCE SSL ##########
RewriteEngine On
RewriteBase / 

# Non-secure requests to www.domain.com should redirect to https://www.domain.com
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.%{HTTP_HOST} [NC]
RewriteRule ^(.*)$ https://www\.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# All secure (HTTPS) traffic should redirect to https://www.domain.com
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.%{HTTP_HOST} [NC]
RewriteRule ^(.*)$ https://www\.%{HTTP_HOST}/$1 [L,R=301] 

</IfModule>

I want to make it as generic a possible so I can simply copy and paste it to any site I make so no need to edit it each time – I guess I could also do this in PHP but I think it would be good if .htaccess is also there.

Another point is, can .htaccess be read if i were to go to http://www.domain.com/.htaccess or do I need to cover that in a ‘deny all’ kind of thing?

  • 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-28T06:23:08+00:00Added an answer on May 28, 2026 at 6:23 am

    The second argument to the RewriteCond must be a regex, so it cannot contain a variable.

    Try adding the following to your .htaccess file in place of the rules you had

    #capture top level domain (.com or .co.uk)
    RewriteCond %{HTTP_HOST} ([-_a-zA-Z0-9]+\.([a-zA-Z]{2,5}|co\.uk))$ [NC]
    RewriteCond %{HTTP_HOST} (www\.)?(.+)$ [NC]
    RewriteRule ^ - [E=MY_TLD:%2]
    
    # Non-secure requests to www.domain.com should redirect to https://www.domain.com
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www\.%{ENV:MY_TLD}%{REQUEST_URI} [L,R=301] 
    
    # All secure (HTTPS) traffic should redirect to https://www.domain.com
    RewriteCond %{HTTPS} on
    #if host does not start with www
    RewriteCond %{HTTP_HOST} !^www\.[-_a-zA-Z0-9]+\.([a-zA-Z]{2,5}|co\.uk)$ [NC]
    RewriteRule ^ https://www\.%{ENV:MY_TLD}%{REQUEST_URI} [L,R=301] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my htaccess file: # Force Trailing Slash RewriteCond
I have the following code in my htaccess file: RewriteEngine On RewriteCond %{HTTP_HOST} !^www.example.com$
i have used the following code in .htaccess Options +FollowSymlinks RewriteEngine On RewriteBase /
I have following Code Block Which I tried to optimize in the Optimized section
I have following code snippet that i use to compile class at the run
After adding the following .htaccess file to my site I noticed that forms had
I have website which works fine and have following in the htaccess file RewriteEngine
I have an htaccess file that is supposed to be redirecting any non-existing files/folders/etc
i have the following .htaccess file for me web Options +FollowSymLinks RewriteEngine on RewriteRule
I have the following code in ://localhost/.htaccess... AddType application/x-httpd-php5 .css .js RewriteEngine on RewriteRule

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.