【问题标题】:Apache RewriteRule patternApache RewriteRule 模式
【发布时间】:2016-02-07 17:23:23
【问题描述】:

我为网络资源管理编写了一个 .htaccess 文件。

我希望这种 URI 模式用于静态资源

^.*/web-console/static/(.*)$

而且,我的 RewriteRule 如下。

RewriteRule "^.*/web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]

而且,我请求低于 URI

http://myhost/shop/web-console/static/css/default.css

但是 Apache 服务器没有匹配 URI。
如果我删除“/web-console”,Apache 工作正常。
下面是重写规则

RewriteRule "^.*/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]

有什么问题?

附录

这是我的目录结构

网络基础 - /data/web
网站基础 - /data/web/shop
htaccess - /data/web/shop/.htaccess
路由器脚本 - /data/web/shop/route.php
静态资源 - /data/web/shop/resources/floworks-web-console-1.0/static
css 文件 - /data/web/shop/resources/floworks-web-console-1.0/static/css/default.css

所以,如果 URI 启动,我希望响应静态资源 /shop/web-console/static
并且,其他情况是使用“RewriteRule .* route.php [L]”传递给路由器脚本

【问题讨论】:

  • 所以 web-console 不是一个真正的目录?
  • 是的,那不是真的

标签: apache .htaccess mod-rewrite


【解决方案1】:

你应该可以这样做。如果你在子文件夹shop 中有这个.htaccess,你应该添加rewritebase。

RewriteEngine On
RewriteBase /shop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule "^web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]

【讨论】:

  • 我需要更多的解释而不是不工作,否则我无法帮助您解决问题。什么不工作?有什么错误吗? .htaccess 文件在哪里?你的资源目录在哪里,在根目录下还是在 shop 下?
  • 哦,对不起我的描述。我的意思是 rewriterule 没有赶上 URI。如果该工作显示我的 default.css 文件内容,但它没有捕获并按照以下语句“RewriteRule .* route.php [L]”工作。
  • 而我的 .htaccess 文件位于 /data/web/shop 文件夹中
  • 而我的default.css文件位于/data/web/shop/resources/floworks-web-console-1.0/static/css/default.css
  • 哪个文件夹被认为是您的 doc root apache?网络或商店?意思是网址 www.example.com/shop?
【解决方案2】:

我找到了自己。

RewriteRule "web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [END]

我会将该标志从 L 更改为 END
谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    相关资源
    最近更新 更多