【问题标题】:Apache rewrite - Virtual dir to php scriptApache 重写 - 到 php 脚本的虚拟目录
【发布时间】:2014-10-01 01:57:06
【问题描述】:

按照post 的公认答案,我构建了一个非常简单的重写规则,但似乎没有按设计工作。

# /st doesn't exist, it's virtual
example.com/st/sometext    

重写为

# /app is a symlink to /app.php, and this link works if entered directly
example.com/app/st/sometext

以及重写规则:

RewriteRule ^st/(.*)$ app/st/$1 [L]

此规则位于重写块的顶部,之后还有其他规则,但由于 [L] 约束,这些规则不应适用。

重写日志文件有这样的:

(2) init rewrite engine with requested uri /st/sometext
(1) pass through /st/sometext

重写规则似乎与 url 不匹配。我错过了什么?

【问题讨论】:

  • 你的解释和你的规则正好相反。您的规则是指rewrite st/XXX to app/st/XXX,这不是您在问题开始时所说的
  • @JustinIurman:谢谢,已更新。

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

好的,我通过切换到 nginx (lol) 并实现了这个重写规则解决了这个问题:

location /st {
    rewrite ^/st/(.*)$ /app.php/st/$1 last;
}

切换到 nginx 与重写规则几乎没有关系,更多的是与摆脱 apache 2.2(centos 的默认上游版本)有关,但是对于 nginx,重写规则比 apache 的 (imo) 更直接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 2018-08-14
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    相关资源
    最近更新 更多