4

我试图让我非常简单的重写规则工作。我正在尝试重写文件系统。

这是我的 htaccess

RewriteEngine On
RewriteRule ^(.*) /var/www/sonarApps/main/com.sonar6.api/account/master/web

这行不通。看起来它总是试图从 apache web root 加载它,所以

/apache/web/root/var/www/sonarApps/main/com.sonar6.api/account/master/web

这是我的日志

10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4f6ed0/initial] (2) init rewrite engine with requested uri /zef-test/master/api/index.php
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4f6ed0/initial] (1) pass through /zef-test/master/api/index.php
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4f6ed0/initial] (3) [perdir /var/www/sonarRoot/zef-test/master/api/] strip per-dir prefix: /var/www/sonarRoot/zef-test/master/api/index.php -> index.php
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4f6ed0/initial] (3) [perdir /var/www/sonarRoot/zef-test/master/api/] applying pattern '^(.*)' to uri 'index.php'
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4f6ed0/initial] (2) [perdir /var/www/sonarRoot/zef-test/master/api/] rewrite 'index.php' -> '/var/www/sonarApps/main/com.sonar6.api/account/master/web'
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4f6ed0/initial] (1) [perdir /var/www/sonarRoot/zef-test/master/api/] internal redirect with /var/www/sonarApps/main/com.sonar6.api/account/master/web [INTERNAL REDIRECT]
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b502f10/initial/redir#1] (2) init rewrite engine with requested uri /var/www/sonarApps/main/com.sonar6.api/account/master/web
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b502f10/initial/redir#1] (1) pass through /var/www/sonarApps/main/com.sonar6.api/account/master/web
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4faef0/initial] (2) init rewrite engine with requested uri /favicon.ico
10.54.1.188 - - [06/Jun/2013:09:26:14 +0500] [...][rid#2b1b8b4faef0/initial] (1) pass through /favicon.ico

阅读 apache mod_rewrite 文档

A full filesystem path to a resource
RewriteRule ^/games /usr/local/games/web
This maps a request to an arbitrary location on your filesystem, much like the Alias directive.

这在我的情况下似乎不起作用。
有任何想法吗?

非常感谢。

4

3 回答 3

3

每个目录规则不支持文件系统重写规则,来自 http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule

file-system path
Designates the location on the file-system of the resource to be delivered to the client. Substitutions are only treated as a file-system path when the rule is configured in server (virtualhost) context and the first component of the path in the substitution is exists in the file-system
于 2013-06-06T22:32:13.857 回答
0

这是正常的:您指定用相同的值替换路径。因此,这种行为是预期的。

您需要将捕获的路径附加到替换中。更重要的是,这里^不需要你的:

RewriteRule (.*) /var/www/sonarApps/main/com.sonar6.api/account/master/web/$1
于 2013-06-06T04:35:09.447 回答
0

重写规则应该在服务器(虚拟主机)上下文中。

因此,您的配置应如下所示

<VirtualHost *> 
...
RewriteEngine On
RewriteRule ^(.*) /var/www/sonarApps/main/com.sonar6.api/account/master/web$1
</VirtualHost>

或者如果你需要它在例如位置,你可能需要定义别名

<VirtualHost *> 

Alias "/masterweb" "/var/www/sonarApps/main/com.sonar6.api/account/master/web"
...
<Location / >
RewriteEngine On
RewriteRule ^(.*) /masterweb$1
</Location>
</VirtualHost>

mod_rewrite.html#rewriterule仅当规则在服务器(虚拟主机)上下文中配置并且替换路径的第一个组件存在于文件系统中时,才会将替换视为文件系统路径。

于 2018-06-15T09:47:15.193 回答