Forum Moderators: phranque

Message Too Old, No Replies

Rewrite not working for SSL Port

         

logic0

4:53 am on Oct 17, 2007 (gmt 0)

10+ Year Member



We have a webserver configured at 80 and 443... All the requests for port 80 is redircted to 443.

But i am tryn to forward requests of 443 to another site..

[xyz.com...] to [example.com...]

RewriteEngine on
RewriteCond {SERVER_PORT} ^443$
RewriteRule ^(.*)$ [example.com...] [R=301,L]

and tried with this too
RewriteEngine on
RewriteCond %{HTTPS}!=on
RewriteRule ^(.*)$ [example.com...] [L,R]

and logs are empty too.

RewriteLogLevel 3
RewriteLog /tmp/blah.txt

It works fine if it is configured at virtual host 80 like below
<VirtualHost *:80>
RewriteCond %{HTTP_HOST} ^www.xyz.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</VirtualHost>

i am using ibm httpd 2.0.47 server....

Any suggestion also welcome

[edited by: jdMorgan at 3:55 pm (utc) on Oct. 17, 2007]
[edit reason] example.com [/edit]

jdMorgan

3:53 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure you're putting the .htaccess code into the DocumentRoot defined for your SSL server.

Note also that the second snippet was wrong: It should read:


and tried with this too
RewriteEngine on
RewriteCond %{HTTPS} [b]= on [NC][/b]
RewriteRule ^(.*)$ https://www.example.com/$1 [b][R=301,L][/b]

Jim

jdMorgan

3:57 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also note that your httpd.conf code will fail if the client appends a port number to the request. It will also create a double-slash on the requested URL-path. It should be coded like this (or similar):

<VirtualHost *:80>
RewriteCond %{HTTP_HOST} ^www\.xyz\.com[b](:[0-9]+)?[/b]$ [NC]
RewriteRule [b]^/[/b](.*)$ http://www.example.com/$1 [R=301,L]
</VirtualHost>

Jim

logic0

6:07 am on Oct 18, 2007 (gmt 0)

10+ Year Member



we dont use htaccess code..
in case if in need to add.. what should i do? could you explain me in steps

".htaccess code into the DocumentRoot defined for your SSL server"

jdMorgan

12:56 pm on Oct 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, make sure you're putting the SSL redirect code into the VirtualHost container that defines your SSL server.

Also, I recommend the version that detects port 443, rather than detecting "%{HTTPS} = on", because "%{HTTPS}" is not a native Apache variable.

Jim

[edited by: jdMorgan at 12:58 pm (utc) on Oct. 18, 2007]