我正在寻找一些帮助来编写RewriteRule来处理dbm值。我有一个dbm文件,其中包含用户标识和主目录路径或网址。 http://www.domain.com/~userid会查找用户ID并返回/ home / userid之类的主目录或http://www.userid.com之类的网址。如果返回主目录,则显示内容。如果返回了一个url,我希望重定向客户端。运行Apache 2.2,我有以下内容:
RewriteEngine On
RewriteLog /etc/httpd/logs/rewrite_log
RewriteLogLevel 4
RewriteMap homedir.dbm dbm:/var/www/data/homedir.dbm
RewriteCond ${homedir.dbm:$1|lookupfailed} (.*)
RewriteCond %1 !lookupfailed
RewriteRule ^/~([^/]+)/(.*)$ /%1/www/$2 [L]
RewriteCond ${homedir.dbm:$1|lookupfailed} (.*)
RewriteCond %1 !lookupfailed
RewriteCond %1 !^http [NC]
RewriteRule ^/~([^/]+)$ /~$1/ [L,R=301]
RewriteCond ${homedir.dbm:$1|lookupfailed} (.*)
RewriteCond %1 !lookupfailed
RewriteCond %1 ^http [NC]
RewriteRule ^/~([^/]+)$ %1 [R]
主目录部分似乎正在工作,但我必须在url重定向部分丢失一些简单的东西。任何和所有的帮助将不胜感激。
答案 0 :(得分:0)
进行了一些小调整,看起来很有效。如果有人看到任何错误或更好的方法,请告诉我。
RewriteEngine On
RewriteLog /etc/httpd/logs/rewrite_log
RewriteLogLevel 4
RewriteMap homedir.dbm dbm:/var/www/data/homedir.dbm
RewriteCond ${homedir.dbm:$1|lookupfailed} (.*)
RewriteCond %1 !lookupfailed
RewriteCond %1 !^http [NC]
RewriteRule ^/~([^/]+)/(.*)$ /%1/www/$2 [L]
RewriteCond ${homedir.dbm:$1|lookupfailed} (.*)
RewriteCond %1 !lookupfailed
RewriteCond %1 ^http [NC]
RewriteRule ^/~([^/]+)/(.*)$ ${homedir.dbm:$1} [L,R]
RewriteCond ${homedir.dbm:$1|lookupfailed} (.*)
RewriteCond %1 !lookupfailed
RewriteCond %1 !^http [NC]
RewriteRule ^/~([^/]+)$ /~$1/ [L,R=301]
RewriteCond ${homedir.dbm:$1|lookupfailed} (.*)
RewriteCond %1 !lookupfailed
RewriteCond %1 ^http [NC]
RewriteRule ^/~([^/]+)$ ${homedir.dbm:$1} [L,R]