【问题标题】:Redirect based on symlink using htaccess使用 htaccess 基于符号链接重定向
【发布时间】:2014-01-04 14:01:24
【问题描述】:

我正在使用 Capistrano 部署 Git 存储库,目前,我在使用 .htaccess 和符号链接设置进行重定向时遇到问题。

这是破败:

  • 我将 dev.example.com 作为 MediaTemple GS 上的子域。
  • 在 dev.example.com 文件夹下,我有客户端文件夹,例如dev.example.com/client
  • 在 dev.example.com/client Capistrano 下有 /releases、/shared、/tmp 和 /current 的符号链接,指向 /releases 文件夹(因此对 /current 的任何访问都始终显示该站点的当前版本)

理想情况下,我希望任何访问 dev.example.com/client 的人都被重定向到该 /current 文件夹,以便它继续遵循符号链接路径。

我将以下内容放在 /client 文件夹中的 .htaccess 中:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^client.*$ /current [L]

但是,它失败了:(

通常会有一个 /html 文件夹,它就像使用以下符号链接一样简单:ln -s ./current ./html 但鉴于这是一个子目录,/html 没有任何意义。 (我想我可以创建一个 /html 目录并弄清楚如何访问 /client 转到 /html,但这似乎很疯狂)。

任何帮助将不胜感激!

【问题讨论】:

    标签: git .htaccess redirect rewrite capistrano


    【解决方案1】:

    如果您已将规则放在 /client 文件夹中,则无需匹配 client,因为它会自动剥离。试试吧:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^$ /current/ [L]
    

    或者,如果您希望对 /client/whatever 的请求也转到 /current/whatever

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^(.*)$ /current/$1 [L]
    

    【讨论】:

    • 嗨,乔恩。感谢您的回复。我最终使用了没有斜杠的 current,因为它是一个符号链接(对于那些使用 Capistrano 的人,他们稍后会阅读此内容),看起来,所以它正在重定向。有没有一种干净的方法让它 dev.example.com/client/ 而不是它显示为 URL 的 dev.example.com/client/current/ ?这是这个难题的最后一块!谢谢。
    猜你喜欢
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    相关资源
    最近更新 更多