Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache rewrite SSL requests

Status
Not open for further replies.

nychris

MIS
Dec 4, 2004
103
US
I'm trying to redirect all requests on a server to a single page that informs the users that the website has been retired. I put this code in the httpd.conf file:

Code:
RewriteEngine on
RewriteRule /* [URL unfurl="true"]https://www.foo.org/Server_Retire_Prompt.html[/URL] [R]

This works as expected for all standard request on port 80. It does not, however, work for any SSL (HTTPS, port 443) requests. How can I redirect all SSL requests as well to the single page?

Thanks
 
We do it this way ....

Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^[URL unfurl="true"]http://([/URL][^:]*):([^/]*)/(.*)
RewriteRule ^(.*)$ [URL unfurl="true"]https://%1:%2/%3[/URL] [P]

In our case our proxy server reads in the http:// url and rewrites it to the same url as https://

IHTH

Laurie.
 
tarn, what I have above already does that. My issue is that it does not work for SSL requests. For example, a user goes to How do I redirect that to another page? It only works for http, not https.
 
Ok sorry I probably misread your post .. so you are listening on https, so have you put the RewriteRule in your ssl port 443 area of the apache config or just in the default port 80 section?

ok guessing here as I have no test server to try but I think you still need RewriteCond in there somewhere

Code:
 RewriteEngine on
 RewriteCond %{HTTP_HOST} ^[URL unfurl="true"]https://www.foo.org$[/URL]
 RewriteRule ^ [URL unfurl="true"]https://www.foo.org/Server_Retire_Prompt.html[/URL] [L,R=301]

So the condition reads requesting host looking for Then the rule says for where we met the condition then rewrite to <your new url> [L (Last rule),R=301 (permanently redirected)]

Well I think that should work ???

IHTH

Laurie.
 
The code you posted doesn't seem to do anything.

The code I originally posted I have in the default section that handles port 80 requests. If I put the same request in the httpd.d/ssl.conf file under the <VirtualHost _default_:443> section, all requests just hang in Internet Explorer. If I use Firefox or Chrome, I get redirect loop errors. This is the redirect error:

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
 
I was able to get this working well enough for what we need it for. I just need to redirect all SSL requests to the same page. I got this working by adding the following to the <VirtualHost _default_:443> section.

Code:
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule ^(.*) [URL unfurl="true"]http://www.server.com/Server_Retire_Prompt.html[/URL] [L,R=301]

When I add this code, the original code I added for HTTP posts doesn't work anymore. That's fine, it's not needed anyway for this project. I am curious why I was not able to redirect both HTTP and HTTPS requests at the same time without getting redirection loop errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top