大网数据广告活动
网站运营与故障问答

Redirect users based on username (LDAP)

· 52CE 我爱测

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…

问题原文

原帖链接 · evachristine · CC BY-SA 3.0

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=[email omitted]
        </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?

社区高分解答

原帖链接 · Jonathan · CC BY-SA 3.0

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 )

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2014-04-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。