Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a website running apache which is accessed

  • internally (rfc1918 address space) as either http://hostname or http://hostname.local
  • externally (public address space) as https://example.org.

How can I redirect access when internal users access from 10.0.1.0/24 address space any page on http://hostname/* or http://hostname.local/* so they are sent to the relevant page on https://hostname.example.org

Caveat being I have two subnets 10.0.1.0/24 which I'd like to do https and 10.0.2.0/24 which I do not want to do https at the moment

What I have at the moment is

RewriteEngine On 
RewriteBase / 
RewriteCond %{REMOTE_HOST} 10\.0\.1 
RewriteRule .* https://hostname.example.org/ [R=301,L] 

But I do not know how to make it so the user gets sent to https://hostname.example.org/test if they go to http://hostname[.local]/test

share|improve this question

2 Answers 2

Try this:

RewriteRule ^(.*)$ https://hostname.example.org/$1 [R=301,L]
share|improve this answer

To make it so that only hits to hostname.local go to there you add the condition HTTP_HOST below and adjust the RewriteRule.

RewriteEngine On 
RewriteBase / 
RewriteCond %{REMOTE_HOST} 10\.0\.1 
RewriteCond %{HTTP_HOST} ^hostname\.local$
RewriteRule ^(.*)$ https://hostname.example.org/$1 [R=301,L]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.