1

Whenever someone visits intern.old-company-name.example.com I would like it to get redirected to https://intern.new-company-name.example.com. One way to do it would be

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*) https://intern.new-company-name.example.com$1
#    RewriteRule ^(.*) https://%{HTTP_HOST}$1                                                             
</IfModule>

but I don't like that I hardcode the outer sub domain intern into the httpd.conf.

Question

Would it be possible to do a regex on %{HTTP_HOST} so old-company-name gets replaced with new-company-name before the redirection to https? Or perhaps something similar?

Update

# apachectl -S
VirtualHost configuration:
10.10.10.10:443     is a NameVirtualHost
         default server a.y.b.com (/etc/httpd/conf.d/ssl.conf:85)
         port 443 namevhost a.y.b.com (/etc/httpd/conf.d/ssl.conf:85)
Syntax OK

2 Answers2

2

Let's have the HTTP to HTTPS behavior handled by the HTTP listener, and the old name to new name behavior handled by the HTTPS listener. (We could have the HTTP redirect also do the name change, but this keeps everything in one place and makes it simpler.)

So, in your main config file we'll put back your original config with a slight tweak:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://${HTTP_HOST}$1

Then inside the <VirtualHost> in /etc/httpd/conf.d/ssl.conf we'll do the name redirect:

RewriteCond %{HTTP_HOST} ^([^\.]+)\.old-company-name\.example\.com$
RewriteRule ^(.*)$ https://%1.new-company-name.example.com$1 [R,L]
Shane Madden
  • 116,404
  • 13
  • 187
  • 256
0

Modifying headers can be done with mod_headers - check http://httpd.apache.org/docs/2.2/mod/mod_headers.html for all the syntax and details. I can't say for sure you can acheive what you want - and I'm not sure really why you want to modify the header in this case.

ETL
  • 6,691
  • 1
  • 32
  • 49