如何在使用通配符的目录指令中使用 apache2 mod_rewrite?
我编写了一个 Web 应用程序,在托管该 Web 应用程序的专用服务器下运行。此 Web 应用程序的实例可在不同的域中使用,每个域都有自己的 Web 应用程序文件副本,允许根据需要进行自定义。
我在 Debian Squeeze 下运行 Apache/2.2.16。
我在 VirtualHost 指令下完成所有配置,并且不使用 .htaccess 文件。
为了简化 apache 配置,我想维护一个目录指令,如下所示:
<Directory "/srv/www/*/public/">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule ^(.+)$ /index.php?q=$1 [L,QSA]
</Directory>
但是,RewriteRule 会产生错误的结果,因为在使用通配符目录值时,它无法去除每个目录的前缀。以下是重写日志的输出:
[rid#b9832078/initial] (3) [perdir /srv/www/*/public/] applying pattern '^(.+)$' to uri '/srv/www/domain1/public/login'
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-f' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-d' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/login' pattern='!=/favicon.ico' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/login' pattern='!=/robots.txt' => matched
[rid#b9832078/initial] (2) [perdir /srv/www/*/public/] rewrite '/srv/www/domain1/public/login' -> '/index.php?q=/srv/www/domain1/public/login'
[rid#b9832078/initial] (3) split uri=/index.php?q=/srv/www/domain1/public/login -> uri=/index.php, args=q=/srv/www/domain1/public/login
[rid#b9832078/initial] (1) [perdir /srv/www/*/public/] internal redirect with /index.php [INTERNAL REDIRECT]
[rid#b9847440/initial/redir#1] (3) [perdir /srv/www/*/public/] applying pattern '^(.+)$' to uri '/srv/www/domain1/public/index.php'
[rid#b9847440/initial/redir#1] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/index.php' pattern='!-f' => not-matched
[rid#b9847440/initial/redir#1] (1) [perdir /srv/www/*/public/] pass through /srv/www/domain1/public/index.php
问题是 RewriteRule 'uri' 是文件系统路径而不是 url 路径,这导致查询字符串不正确:q=/srv/www/domain1/public /login
像这样显式指定目录路径:
<Directory "/srv/www/domain1/public/">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule ^(.+)$ /index.php?q=$1 [L,QSA]
</Directory>
工作得很好,这里是重写日志的输出,显示了正确的行为(区别在于新的第一附加行为重写的其余部分提供了正确的输入结果在正确的查询字符串中:q=login):
[rid#b9868048/initial] (3) [perdir /srv/www/domain1/public/] strip per-dir prefix: /srv/www/domain1/public/login -> login
[rid#b9868048/initial] (3) [perdir /srv/www/domain1/public/] applying pattern '^(.+)$' to uri 'login'
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-f' => matched
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-d' => matched
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/login' pattern='!=/favicon.ico' => matched
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/login' pattern='!=/robots.txt' => matched
[rid#b9868048/initial] (2) [perdir /srv/www/domain1/public/] rewrite 'login' -> '/index.php?q=login'
[rid#b9868048/initial] (3) split uri=/index.php?q=login -> uri=/index.php, args=q=login
[rid#b9868048/initial] (1) [perdir /srv/www/domain1/public/] internal redirect with /index.php [INTERNAL REDIRECT]
[rid#b987d5f8/initial/redir#1] (3) [perdir /srv/www/domain1/public/] strip per-dir prefix: /srv/www/domain1/public/index.php -> index.php
[rid#b987d5f8/initial/redir#1] (3) [perdir /srv/www/domain1/public/] applying pattern '^(.+)$' to uri 'index.php'
[rid#b987d5f8/initial/redir#1] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/srv/www/domain1/public/index.php' pattern='!-f' => not-matched
[rid#b987d5f8/initial/redir#1] (1) [perdir /srv/www/domain1/public/] pass through /srv/www/domain1/public/index.php
我希望我遇到 Apache 的错误,但如果情况并非如此,我做错了什么?
虽然我很欣赏将方法更改为另一个可行解决方案的意见,但我会接受以我所采取的方法(例如不使用 .htaccess)解决该问题的答案,除非可以证明这种方法无法解决。
那么,在通配符目录中使用时,是否需要更改 RewriteCond/Rules 的某些内容?
好奇的旁注:为了进一步简化,我使用 VirtualDocumentRoot 来使用单个 VirtualHost - 但这是无关的,因为这个问题是通过使用“DocumentRoot”和在单个域下进行测试来复制的。
编辑
好的,我已经根据regilero的回答重新审视了这一点,这就是发生的情况 - 将重写按原样移出目录会导致轻微的初始影响查询字符串从“login”更改为“/login”的问题,可以通过将 RewriteRule 修改为: RewriteRule ^/(.+)$ /index.php?q=$1 来解决此问题[L,QSA]
修复了我之前的“莫名其妙地失败”评论。
接下来,所有静态文件都无法加载,这是显示此问题的重写日志:
[rid#b7bc7fa0/initial] (2) init rewrite engine with requested uri /login
[rid#b7bc7fa0/initial] (3) applying pattern '^/(.+)$' to uri '/login'
[rid#b7bc7fa0/initial] (4) RewriteCond: input='/login' pattern='!-f' => matched
[rid#b7bc7fa0/initial] (4) RewriteCond: input='/login' pattern='!-d' => matched
[rid#b7bc7fa0/initial] (4) RewriteCond: input='/login' pattern='!=/favicon.ico' => matched
[rid#b7bc7fa0/initial] (4) RewriteCond: input='/login' pattern='!=/robots.txt' => matched
[rid#b7bc7fa0/initial] (2) rewrite '/login' -> '/index.php?q=login'
[rid#b7bc7fa0/initial] (3) split uri=/index.php?q=login -> uri=/index.php, args=q=login
[rid#b7bc7fa0/initial] (2) local path result: /index.php
[rid#b7bc7fa0/initial] (2) prefixed with document_root to /srv/www/domain1/public/index.php
[rid#b7bc7fa0/initial] (1) go-ahead with /srv/www/domain1/public/index.php [OK]
[rid#b7be6b80/initial] (2) init rewrite engine with requested uri /static/css/common.css
[rid#b7be6b80/initial] (3) applying pattern '^/(.+)$' to uri '/static/css/common.css'
[rid#b7be6b80/initial] (4) RewriteCond: input='/static/css/common.css' pattern='!-f' => matched
[rid#b7be6b80/initial] (4) RewriteCond: input='/static/css/common.css' pattern='!-d' => matched
[rid#b7be6b80/initial] (4) RewriteCond: input='/static/css/common.css' pattern='!=/favicon.ico' => matched
[rid#b7be6b80/initial] (4) RewriteCond: input='/static/css/common.css' pattern='!=/robots.txt' => matched
[rid#b7be6b80/initial] (2) rewrite '/static/css/common.css' -> '/index.php?q=static/css/common.css'
[rid#b7be6b80/initial] (3) split uri=/index.php?q=static/css/common.css -> uri=/index.php, args=q=static/css/common.css
[rid#b7be6b80/initial] (2) local path result: /index.php
[rid#b7be6b80/initial] (2) prefixed with document_root to /srv/www/domain1/public/index.php
[rid#b7be6b80/initial] (1) go-ahead with /srv/www/domain1/public/index.php [OK]
但是就像我在对 regilero 的回答的评论中所说,这是通过在 RewriteCond 指令 TestString 前加上 % 前缀来解决的{DOCUMENT_ROOT}。但是,在使用 VirtualDocumentRoot 时,使用 %{DOCUMENT_ROOT} 不起作用。
在我看来,%{DOCUMENT_ROOT} 前缀是必要的,这似乎不正确。
编辑
REQUEST_FILENAME
与匹配的文件或脚本的完整本地文件系统路径 请求,如果服务器当时已经确定了这一点 引用了 REQUEST_FILENAME。否则,例如当用于 虚拟主机上下文,与 REQUEST_URI 的值相同。
这解释了 DOCUMENT_ROOT 前缀的需要。
我已将重写规则更新为:
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteCond %{REQUEST_URI} !^/static/
RewriteRule ^/(.+)$ /index.php?q=$1 [PT,L,QSA]
可以正常工作(注意:PT 标志是必要的,以避免在使用 VirutalDocumentRoot 时过早地将 url 路径转换为文件系统路径)。这里行为的主要变化是应用程序的所有入口点都需要 RewriteCond - 类似于 /static 行。
编辑
这是我在任何目录指令之外的 VirtualHost 中重写指令的最终体现:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/static/
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule ^/(.+)$ /index.php?q=$1 [NS,PT,L,QSA]
RewriteRule ^/$ /index.php [NS,PT,L,QSA]
我添加了 NS
标志以避免额外的内部评估,并添加了第二个 < code>RewriteRule 指令支持使用 mod_dir 和 DirectoryIndex
。我的应用程序不需要 root url 的 q= 参数,否则需要一个 RewriteRule
的 RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,如果应用程序已更新为接受根 URL 的空
就足够了。我将来可能会这样做。q=
参数,QSA]
I have written a web application which I run under a dedicated server for hosting the web application. Instances of this web application are available at different domains, and each domain has its own copy of the web application files, allowing for customization as necessary.
I'm running Apache/2.2.16 under Debian Squeeze.
I do all of the configuration under a VirtualHost directive and do not use .htaccess files.
To simplify the apache configuration, I am wanting to maintain a single Directory directive like such:
<Directory "/srv/www/*/public/">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule ^(.+)$ /index.php?q=$1 [L,QSA]
</Directory>
However, the RewriteRule produces the wrong results because while using the wildcard Directory value, it fails to strip the per-directory prefix. Here is the output of the rewrite log:
[rid#b9832078/initial] (3) [perdir /srv/www/*/public/] applying pattern '^(.+)
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
<Directory "/srv/www/domain1/public/">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule ^(.+)$ /index.php?q=$1 [L,QSA]
</Directory>
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
[rid#b9868048/initial] (3) [perdir /srv/www/domain1/public/] strip per-dir prefix: /srv/www/domain1/public/login -> login
[rid#b9868048/initial] (3) [perdir /srv/www/domain1/public/] applying pattern '^(.+)
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
[rid#b7bc7fa0/initial] (2) init rewrite engine with requested uri /login
[rid#b7bc7fa0/initial] (3) applying pattern '^/(.+)
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteCond %{REQUEST_URI} !^/static/
RewriteRule ^/(.+)$ /index.php?q=$1 [PT,L,QSA]
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/static/
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule ^/(.+)$ /index.php?q=$1 [NS,PT,L,QSA]
RewriteRule ^/$ /index.php [NS,PT,L,QSA]
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
to uri '/srv/www/domain1/public/login'
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-f' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-d' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/login' pattern='!=/favicon.ico' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/login' pattern='!=/robots.txt' => matched
[rid#b9832078/initial] (2) [perdir /srv/www/*/public/] rewrite '/srv/www/domain1/public/login' -> '/index.php?q=/srv/www/domain1/public/login'
[rid#b9832078/initial] (3) split uri=/index.php?q=/srv/www/domain1/public/login -> uri=/index.php, args=q=/srv/www/domain1/public/login
[rid#b9832078/initial] (1) [perdir /srv/www/*/public/] internal redirect with /index.php [INTERNAL REDIRECT]
[rid#b9847440/initial/redir#1] (3) [perdir /srv/www/*/public/] applying pattern '^(.+)
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
to uri '/srv/www/domain1/public/index.php'
[rid#b9847440/initial/redir#1] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/index.php' pattern='!-f' => not-matched
[rid#b9847440/initial/redir#1] (1) [perdir /srv/www/*/public/] pass through /srv/www/domain1/public/index.php
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
to uri 'login'
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-f' => matched
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-d' => matched
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/login' pattern='!=/favicon.ico' => matched
[rid#b9868048/initial] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/login' pattern='!=/robots.txt' => matched
[rid#b9868048/initial] (2) [perdir /srv/www/domain1/public/] rewrite 'login' -> '/index.php?q=login'
[rid#b9868048/initial] (3) split uri=/index.php?q=login -> uri=/index.php, args=q=login
[rid#b9868048/initial] (1) [perdir /srv/www/domain1/public/] internal redirect with /index.php [INTERNAL REDIRECT]
[rid#b987d5f8/initial/redir#1] (3) [perdir /srv/www/domain1/public/] strip per-dir prefix: /srv/www/domain1/public/index.php -> index.php
[rid#b987d5f8/initial/redir#1] (3) [perdir /srv/www/domain1/public/] applying pattern '^(.+)
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
to uri '/srv/www/domain1/public/login'
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-f' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/login' pattern='!-d' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/login' pattern='!=/favicon.ico' => matched
[rid#b9832078/initial] (4) [perdir /srv/www/*/public/] RewriteCond: input='/login' pattern='!=/robots.txt' => matched
[rid#b9832078/initial] (2) [perdir /srv/www/*/public/] rewrite '/srv/www/domain1/public/login' -> '/index.php?q=/srv/www/domain1/public/login'
[rid#b9832078/initial] (3) split uri=/index.php?q=/srv/www/domain1/public/login -> uri=/index.php, args=q=/srv/www/domain1/public/login
[rid#b9832078/initial] (1) [perdir /srv/www/*/public/] internal redirect with /index.php [INTERNAL REDIRECT]
[rid#b9847440/initial/redir#1] (3) [perdir /srv/www/*/public/] applying pattern '^(.+)
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
to uri '/srv/www/domain1/public/index.php'
[rid#b9847440/initial/redir#1] (4) [perdir /srv/www/*/public/] RewriteCond: input='/srv/www/domain1/public/index.php' pattern='!-f' => not-matched
[rid#b9847440/initial/redir#1] (1) [perdir /srv/www/*/public/] pass through /srv/www/domain1/public/index.php
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
to uri 'index.php'
[rid#b987d5f8/initial/redir#1] (4) [perdir /srv/www/domain1/public/] RewriteCond: input='/srv/www/domain1/public/index.php' pattern='!-f' => not-matched
[rid#b987d5f8/initial/redir#1] (1) [perdir /srv/www/domain1/public/] pass through /srv/www/domain1/public/index.php
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
The problem is that the RewriteRule 'uri' is the filesystem path rather than the url path, which results in the query string being incorrect: q=/srv/www/domain1/public/login
Explicitly specifying the Directory path like such:
Works just fine, and here is the output of the rewrite log showing the correct behavior (the difference being the new first additional line providing the correct input to the rest of the rewrite resulting in the correct query string: q=login):
I expect I'm running into a bug with Apache, but if that isn't the case, what am I doing wrong?
While I appreciate input to changing the approach to another workable solution, I'd accept an answer that solves it in the approach I've taken (eg not using .htaccess) unless it can be shown this approach is not solvable.
So is there something that has to change to the RewriteCond/Rules when used within a wildcard Directory?
Side note for the curious: For further simplification I use a single VirtualHost using VirtualDocumentRoot - however this is unrelated as this issue is replicated with using 'DocumentRoot' and testing under a single domain.
EDIT
Ok, I've revisited this based on regilero's answer and here is what occurs - moving the Rewrite, as is, out of the Directory results in a slight initial problem of the query string changing from "login" to "/login", this is fixed by modifying the RewriteRule to be: RewriteRule ^/(.+)$ /index.php?q=$1 [L,QSA]
which fixes my previous "inexplicably fails" comment.
Following that, all static files fail to load, here is the rewrite log showing this problem:
But like I said in my comment to regilero's answer, this is solved by prefixing the RewriteCond directives TestString with %{DOCUMENT_ROOT}. However, using %{DOCUMENT_ROOT} does not work when using VirtualDocumentRoot.
It does not seem right to me that the %{DOCUMENT_ROOT} prefix should be necessary.
EDIT
REQUEST_FILENAME
The full local filesystem path to the file or script matching the
request, if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in
virtual host context, the same value as REQUEST_URI.
which explains the need for the DOCUMENT_ROOT prefix.
I've updated the rewrite rules to this:
Which works ok (Note: the PT flag is necessary to avoid prematurely translating the url path to a file system path when using VirutalDocumentRoot). The main change in behavior here is that a RewriteCond will be necessary for all entry points into the application - similar to the /static line.
EDIT
Here is my final incarnation of Rewrite directives in the VirtualHost outside of any Directory directives:
I've added the NS
flag to avoid an extra internal evaluation and added the second RewriteRule
directive in favor of using mod_dir and DirectoryIndex
. My application expects no q= parameter for the root url, else a single RewriteRule
of RewriteRule ^/(.*)$ /index.php?q=$1 [NS,PT,L,QSA]
would be sufficient if the application was updated to accept an empty q=
parameter for the root url. I may do that in the future.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常好的且详细的问题。
您肯定遇到了错误,或者至少遇到了未记录的 rewriteRule 域。文件指出:
因此,没有提及带有通配符的
指令将无法删除每个目录的前缀。使用 RewriteBase 对你没有帮助,它是为了重建最终的 Url 而不是改变 perdir 的工作。但正如您在开头所看到的,有“具有一些额外的复杂性”句子。 由 mod-rewrite 完成的目录操作比一般的目录外 RewriteRules 更慢且更复杂。这个文档也说明了这一点,主要是因为Perdir 条带操作。这意味着您还可以在 VirtualHost 中的
部分中编写 rewriteRule。index.php?q=$1
规则,则可能会产生一些副作用。但我很确定这对你来说不是问题。因此,只需编写(不带通配符目录):
它应该可以工作,如果这会导致新问题,请告诉我。
编辑:
好吧,忘记了 REQUEST_FILENAME 尚未在 VirtualHost 上下文中完整定义的事实,它已记录在案,它是“正常”,当应用条件时,文件搜索将在实际情况下进行路径还没有完成,这就是为什么你必须添加文档根目录。因此,实际上您的最终解决方案应该是:
我尝试了第二种解决方案,通过使用REQUEST_FILENAME的后期评估来避免 DOCUMENT_ROOT ( %{LA-U:REQUEST_FILENAME} 包含最终路径,这实际上是如果文件不存在,则为index.php的完整路径),但我让它工作的唯一方法是在第二个规则中添加第二个规则和一个或条件,不太简单,所以第一个解决方案肯定更好(吻)。
Very nice and detailled question.
You have quite certainly hit a bug, or at least an undocumented rewriteRule domain. Documentation states that:
So no mention of the fact
<Directory>
instruction with wildcards won't be able to strip the per-directory prefix. And playing with RewriteBase won't help you, it's done to rebuild final Url not alter the perdir work.But as you can see on the start there's the "with some additional complexity" sentence. Directory manipulations done by mod-rewrite are slower and more complex than general out-of-directory RewriteRules. This is stated as well in this documentation, mainly because of the perdir strip manipulation. And this means you can also write your rewriteRule out of the
<Directory>
section, in your VirtualHost.index.php?q=$1
rule in some other directories. But I'm quite sure this is not a problem in your case.So simply write (without the wildcard directory):
And it should work, let me known if this leads to new problems.
Edit:
Ok, forogot the fact REQUEST_FILENAME is not yet complelty defined in VirtualHost context, it's documented, it's 'normal', when the condition is applied the file search on the real path is not done yet, this is why you must add the document root. So in fact your final solution should be :
I tried a second one, avoiding DOCUMENT_ROOT, by using late evaluation of REQUEST_FILENAME ( %{LA-U:REQUEST_FILENAME} contains the final path, which is in fact the full path to index.php in case of non existent files), but the only way I got it working is by adding a second Rule and a Or condition in the second, less simple, so the first solution is certainly better (KISS).