dppx9253 2015-08-30 15:00
浏览 39
已采纳

如何设置环境变量,然后重定向当前目录,以允许公共代码

I am trying to modernize an older website that has three sections corresponding to three different sets of users: a public section for everybody, a members section for logged-in users, and an admin section for administrators. I'm running into trouble using one login script for both the members and the admins.

My directory structure currently looks like this:

/mysite <- for everyone
/mysite/member
/mysite/admin
/mysite/common/login

For login, I've installed the HUGE user authentication script by Panique (https://github.com/panique/huge). HUGE sets configuration variables using a file named config.{environment variable}.php.

The database has two different user tables-- one "members" table with user information, one "admins" table for administrators . I'd like to keep this table structure because I don't want to edit hundreds of files to reflect the change.

If I edit .htaccess in /mysite, I can set the environment variable, then redirect hits on /mysite/member to go to /mysite/common/login as follows (I use 302 because I'm still messing around):

 SetEnv APPLICATION_ENV admin
 RewriteRule ^admin common/login/public [R=302,NC,L] 

It works okay so far. It sets the environment variable, jumps to /mysite/common/login/public, then HUGE loads config.admin.php. Then I can set the users table and path variables in config.admin.php. I'm able to log in although haven't gotten as far as to access the files in admin.

Right now, I can't figure out how to set the environment variable for both admin and members. Among other things, I tried creating the following .htaccess files but they didn't work. In /mysite/admin:

SetEnv APPLICATION_ENV admin
RewriteEngine On
RewriteRule * common/login/public [R=302,NC,L]

In /mysite/member:

 SetEnv APPLICATION_ENV member
 RewriteEngine On
 RewriteRule * common/login/public [R=302,NC,L]

I know that my RewriteRule syntax is wrong at the least, but it may also be wrong to do these redirects at all. Will I be able to access files in admin and member once logged in, or will they keep rewriting to common/login/public?

P.S. I am open to alternatives to get the job done in a simpler way. The fast and dirty way to get the job done would be to just duplicate the login script so each section has its own copy. But I'd like to avoid this.

  • 写回答

1条回答 默认 最新

  • dongpao1083 2015-08-31 00:19
    关注

    Put the following contents in .htaccess in /mysite directory.

    RewriteEngine On
    RewriteRule ^(admin|member) common/login/public [E=APPLICATION_ENV:$1,R=302,NC,L]
    

    Where the E flag sets the environment variable APPLICATION_ENV to the value stored in $1 which can be either admin or member.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么