Quick httpd redirect question

Jon J ubuntu-users at mlist.ca
Thu Feb 21 10:49:16 UTC 2013


Hi Olly,

I'm assuming you're using Apache, and guessing your redirect is currently
done in an .htaccess file.
If you could use PHP instead then you could access the server's address
with the server variable $_SERVER['SERVER_ADDR'] and use a header()
statement to send the browser a redirect.

See http://php.net/manual/en/reserved.variables.server.php and
http://php.net/manual/en/function.header.php

Your code would probably look something like

<?php
    header('Location: https://' . $_SERVER['SERVER_ADDR'], true, 301);
?>

Stick that in index.php in the root directory of your server and you've got
a start. It'll only redirect requests to the bare domain though... if you
want to redirect ALL non-HTTPS site requests then you might need something
in .htaccess to rewrite them all to index.php

Also if you're serving the same directory for both protocols, you might
need to do some work with $_SERVER['HTTPS'] to detect how you got here.

Jon


On Thu, Feb 21, 2013 at 1:20 AM, Oliver Marshall <
oliver.marshall at g2support.com> wrote:

> Hi Chaps
>
> Not quite the right list I know but I have a quick HTTPD redirect
> question.
>
> I have a redirect line that redirects all HTTP requests to the HTTPS IP of
> my little test server.
>
> Currently it has a fixed internal IP.
>
> I need to change the redirect line so that it will redirect to whatever
> the current IP of the server is, rather than a fixed IP.
>
> That is, the server itself will be going to a client for testing, but they
> have DHCP only and no access to the DHCP service to assign a static IP.
> They also have no internal DNS. They work from a serviced office and the
> serviced office hardware just hands out IPs. As such the IP of the server
> will change every 4 to 8 hours or so and I need the redirect to be able to
> redirect to whatever the current IP address is.
>
> Can that be done?
>
> Olly
>
> Network Support
> Online Backups
> Server Management
>
> Tel: 0845 307 3443
> Web: http://www.g2support.com
> Twitter: g2support <http://twitter.com/home?status=@g2support>
> Google+: http://www.g2support.**com/plus <http://www.g2support.com/plus>
> Facebook: http://www.facebook.com/**g2support<http://www.facebook.com/g2support>
> Mail: Unit H, Hove Technology Centre, Hove, Sussex, BN3 7ES
>
> Have you said something nice about us to a friend or colleague ? Let us
> say thanks. Find out more at www.g2support.com/referral
>
> G2 Support LLP is registered at Mill House, 103 Holmes Avenue, HOVE
> BN3 7LE. Our registered company number is OC316341.
>
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20130221/2643cd0f/attachment.html>


More information about the ubuntu-users mailing list