Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
Force SSL + www + Subdirectory with .htaccess

I have the following domains:

http://example.net    -> https://www.example.com/
http://example.org    -> https://www.example.com/
http://example.com    -> https://www.example.com/
http://theexample.com -> https://www.example.com/

I'm lost looking for a way to be able to force redirect all these domains to a single domain that uses www and https including all subdirectories. The main domain is example.com and I need to redirect it including subdirectories like:

http://example.net/blog     -> https://www.example.com/blog
http://www.example.org/blog -> https://www.example.com/blog
https://example.com/blog    -> https://www.example.com/blog
http://theexample.com/blog  -> https://www.example.com/blog

https://www and the domain example.com is mandatory all subdirectories.

Thank you in advance for your help

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Rather than checking for the hostnames to redirect, you could instead just check that the scheme + hostname is not the canonical and then redirect to it. So, if the request is not for https://www.example.com/... then redirect (copying the URL-path).

For example:

RewriteEngine On

RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule (.*) https://www.example.com/$1 [R=302,L]

The above states... for all requests where HTTPS is either off or not www.example.com then redirect to https://www.example.com/<URL-path>. $1 is a backreference to the capturing subgroup in the RewriteRule pattern (ie. the URL-path). Any query string is also copied through by default.

The = prefix on the CondPattern makes this an exact string match, not a regex. And the ! prefix negates the regex (ie. does not match).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!