Answers for "Using mod_rewrite Configuration to Change Requests from NON-SSL to SSL"

0

Using mod_rewrite Configuration to Change Requests from NON-SSL to SSL

Using mod_rewrite Configuration to Change Requests from NON-SSL to SSL

Oracle HTTP Server - Version 12.2.1.4.0 and later
Information in this document applies to any platform.
SYMPTOMS
Using mod_rewrite configuration to change requests from non-ssl to ssl, does not work for multiple sites/virtual hosts.
Configuration works for one site but the other site is rewritten back to the first site.

The issue can be seen using the following steps:

1. Set configuration in the OHS Configuration as follows:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R,L]


2. Start OHS.


3. Test requests.


4. Does not work as expected. It is seen that it works for one of the site definitions in a VirtualHost, but not for others.



CAUSE
Issue is expected based on configuration. There is no way to have two different global Server Names so the issue occurs sending requests to one virtual host.
The SERVER_NAME variable is set based on the configuration of ServerName Directive in the OHS configuration. Since there is one global variable, if set twice the
variable is reset. It can only be one value in relation to global/main configuration. This is why all requests are sent to the same SERVER_NAME and the issue is seen.


Reference the following document from Apache which Oracle HTTP Server is built from:

Apache HTTP Server Version 2.4
https://httpd.apache.org/docs/current/mod/mod_rewrite.html
Apache Module mod_rewrite
 

SOLUTION
1) Backup and modify httpd.conf or configuration where this is defined.

2) Add the following rewrite config pertaining to the different Sites/VirtualHosts:


RewriteEngine On
RewriteCond %{SERVER_PORT} xx
RewriteCond "%{HTTP_HOST}" "^xxx"
RewriteRule ^/(.*)$ https://xxx/$1 [R,L]

RewriteCond %{SERVER_PORT} yy
RewriteCond "%{HTTP_HOST}" "^yyy"
RewriteRule ^/(.*)$ https://yyy/$1 [R,L]


3) Restart OHS.

4) Test accessing respective sites.



REFERENCES
NOTE:603796.1 - How to Force HTTP Requests to be Redirected to HTTPS
Posted by: Guest on May-19-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language