Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如果请求自身,则重写规则无法按预期工作_Regex_Apache2 - Fatal编程技术网

Regex 如果请求自身,则重写规则无法按预期工作

Regex 如果请求自身,则重写规则无法按预期工作,regex,apache2,Regex,Apache2,我想服务 http://172.16.0.2/container/app.html/any/path/here 通过app.html这是一个现有的资源 另外,我希望没有任何结尾扩展的所有路径都由index.html提供服务。即:http://172.16.0.2/container/path/randomly/written 以下是我的规则: Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_URI}::$1 ^(/.+)/

我想服务

http://172.16.0.2/container/app.html/any/path/here
通过
app.html
这是一个现有的资源

另外,我希望没有任何结尾扩展的所有路径都由
index.html
提供服务。即:
http://172.16.0.2/container/path/randomly/written

以下是我的规则:

Options -MultiViews

RewriteEngine On

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteRule ^[^.]{1}(?!<\.)[^.]{1,}$   index.html [L]

RewriteRule ^app.html$   - [L]
RewriteRule ^app.html(.*)$   app.html [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule - [L]

问题是这些规则被设置为
指令,在
指令之前设置的一些
重写规则之后,直接进入
指令

根据,如果我在其中设置了
RewriteRule
,我只能通过指定URLs来重写。不过,我是通过考虑物理路径来指定的

指定要删除的资源在文件系统上的位置 交付给客户。替换仅被视为一种替代 在服务器(virtualhost)中配置规则时的文件系统路径 上下文,替换中路径的第一个组件是 存在于文件系统中

两种解决方案:

  • 关于URL重写的思考
  • 将RewriteRule移到
    指令之外,以便apache将替换视为物理路径

问题在于,这些规则被设置为
指令,在
指令之前设置的一些
重写规则之后,直接设置为
指令

根据,如果我在其中设置了
RewriteRule
,我只能通过指定URLs来重写。不过,我是通过考虑物理路径来指定的

指定要删除的资源在文件系统上的位置 交付给客户。替换仅被视为一种替代 在服务器(virtualhost)中配置规则时的文件系统路径 上下文,替换中路径的第一个组件是 存在于文件系统中

两种解决方案:

  • 关于URL重写的思考
  • 将RewriteRule移到
    指令之外,以便apache将替换视为物理路径

试过这个吗@好的,我用一些有用的日志更新了这个问题@好的,我用一些有用的日志更新了这个问题
172.16.0.1 - - [27/Jul/2016:10:44:40 +0000] [172.16.0.2/sid#7fc44d87d4c0][rid#7fc44dbd10b8/initial] (3) [perdir /var/www/html/applications/container/web/] add path info postfix: /var/www/html/applications/container/web/app.html -> /var/www/html/applications/container/web/app.html/sdf/sdf
172.16.0.1 - - [27/Jul/2016:10:44:40 +0000] [172.16.0.2/sid#7fc44d87d4c0][rid#7fc44dbd10b8/initial] (3) [perdir /var/www/html/applications/container/web/] strip per-dir prefix: /var/www/html/applications/container/web/app.html/sdf/sdf -> app.html/sdf/sdf
172.16.0.1 - - [27/Jul/2016:10:44:40 +0000] [172.16.0.2/sid#7fc44d87d4c0][rid#7fc44dbd10b8/initial] (3) [perdir /var/www/html/applications/container/web/] applying pattern '^app.html(.*)$' to uri 'app.html/sdf/sdf'
172.16.0.1 - - [27/Jul/2016:10:44:40 +0000] [172.16.0.2/sid#7fc44d87d4c0][rid#7fc44dbd10b8/initial] (2) [perdir /var/www/html/applications/container/web/] rewrite 'app.html/sdf/sdf' -> 'app.html'
172.16.0.1 - - [27/Jul/2016:10:44:40 +0000] [172.16.0.2/sid#7fc44d87d4c0][rid#7fc44dbd10b8/initial] (3) [perdir /var/www/html/applications/container/web/] add per-dir prefix: app.html -> /var/www/html/applications/container/web/app.html
172.16.0.1 - - [27/Jul/2016:10:44:40 +0000] [172.16.0.2/sid#7fc44d87d4c0][rid#7fc44dbd10b8/initial] (1) [perdir /var/www/html/applications/container/web/] initial URL equal rewritten URL: /var/www/html/applications/container/web/app.html [IGNORING REWRITE]