0
votes

I have to redirect from one domain to another domain. Both the domains have http and https protocol enabled. so in order to map http and https i have tried various combinations in conf file as below: #RewriteCond %{HTTPS} =on #RewriteCond %{SERVER_PORT} ^443$ #RewriteRule ^(.+)$ - [env=askapache:https]

#RewriteCond %{HTTPS} !=on
#RewriteRule ^(.+)$ - [env=askapache:http]
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.+)$ - [env=askapache:%2]

RewriteCond %{HTTP_HOST} ^([www.]+)?test-redirect\.com$ [NC]  
RewriteRule  ^(.*)$ http%{ENV:askapache}//amit.test.com/content/test/category/6  [L]

#RewriteCond %{HTTP_HOST} ^([www.]+)?test-redirect\.com$ [NC]  <BR> 
#RewriteCond %{HTTPS} !on
#RewriteRule .? http://amit.test.com/content/test/category/6 [L]`

But every time https condition is skipped/ignored. there is nothing rewrite logs as well. i have seen so many examples on net. but fail to understand why it is not detecting https? where http is working perfectly fine.

1

1 Answers

0
votes
  • Rewrite logs may very well be in 2 diff locations for https and http. You can try using HTTP_AA instead of using "askapache" for the name of the env. The prefix HTTP_ANYTHING is a more fail safe way to make sure the var is available since some setups don't allow custom vars that start with anything other than HTTP_ which they have to allow due to it represents a HTTP header usually.

  • Make sure your https port is actually 443 or you will need to change the code.

  • Make sure your mod_rewrite block of code works by trying the first and second methods here: Even Newer HTTP/HTTPS Rewrite Code If it doesn't work using the first example you need to get it working using that rule first.

  • Try setting the HTTP_AA var above the rewrite code using the SetEnvIfNoCase directive or with

    SetEnv HTTP_AA

  • Verify your vhost/httpd.conf settings for both SSL and non-SSL like the document root and Options and AllowOverrides, Logs and maybe StdEnvVars for SSLOptions.

  • Build a shtml file using mod_includes that just does a printenv. Then view both the ssl and non-ssl outputs and pay particular attention to the vars with the prefix REDIRECT_ and obviously make sure the HTTP_AA var shows up correctly in the printenv output. Or you could use the printenv cgi script or the shtml example on the askapache site.

  • Don't forget http://httpd.apache.org/.

Or try this

    Options +FollowSymLinks +ExecCGI

    # Set var now to try to try to have it availabe for mod_rewrite
    SetEnv HTTP_AA

    RewriteEngine On
    RewriteBase /

    # HTTP_AA is set to either s or is blank
    RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
    RewriteRule ^(.+)$ - [env=HTTP_AA:%2]

    # if host not new domain, its old so redirect both http/https to new
    RewriteCond %{HTTP_HOST} !^amit\.example\.com$ [NC]
    RewriteRule  .* http%{ENV:HTTP_AA}://amit.example.com/content/test/category/6  [R=301,L]