Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

We have an apache 2.2 install with this config on an Ubuntu 12.04:

cat /etc/apache2/sites-enabled/000-default
<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
        <Directory />
            AuthType Basic
            AuthName "Please provide USERNAME AND PASSWORD!"
            AuthBasicProvider ldap
            Order allow,deny
            Allow from all
            AuthLDAPURL "ldap://foo.com/c=uk,ou=bar,o=foo.com?mail"
            Require valid-user
            Require ldap-attribute dept=4F4623
            Require ldap-attribute emailAddress=someone@somewhere.com
        </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel info
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride None
            Order deny,allow
            Deny from all
            Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>

It's working great with LDAP auth! We have ldap-utils, php5, apache2.2-common.

Question:

How can we create a page, so for example:

somedomain.com/selectorpage.html

redirects the logged in user to another page based on their username?

So if XY user visits the "selectorpage.html", then it will be redirected immediately to page XY.html. If AB user visits the "selectorpage.html", then it will be redirected immediately to page AB.html. Or are there any apache redirects for this?

share|improve this question
1  
Only an idea, I've not tried this: Set the REMOTE_USER variable to the logged-in user (AuthLDAPRemoteUserAttribute could help), and then use mod_rewrite to redirect: Use a condition RewriteCond %{REMOTE_USER} (.*) to get the user name, and redirect using a backreferencing rewrite-rule after that: RewriteRule .* /%1.html, where %1 will be replaced with the username. –  Jost May 10 at 17:42

1 Answer 1

combining this post with your information, Id suggest you use a php page, instead of an html page in place of selector page.html, and using

$_SERVER['PHP_AUTH_USER']

inside the selector_page.php with either:

switch($_SERVER['PHP_AUTH_USER']){
    case "user_a":
        $url = "xy.html";
        break;
    ......
    case "user_n":
        $url = "nn.html";
        break;
    default:
        $url = "ab.html";
        break;
}
header("location: $url");

or similar

( you might need to do a mod_rewrite rule to change the selectorpage.html to selectorpage.php if its an external link and not under your control, but it would be better to change the link to point to the php page if its not )

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.