如何解决Apache 2.4 mod_rewrite添加不必要的和不需要的路径信息后缀?

时间:2017-07-26 09:41:13

标签: apache mod-rewrite url-rewriting

.htaccess的相关部分:(所有其他人已注释掉)

Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /somesite/

...

# All non-directory requests should go to /web/
RewriteCond %{REQUEST_URI} !/(web|cms|shared)/.*$
RewriteRule ^(.*)$ web/$1

...

# Language is irrelevant for resource passthrough. Strip it.
RewriteRule ^web/(en|nl)/(.*)$ web/$2

...

为了简化案例,所有未显示的内容也会被注释掉,因此不会影响案例。

请求: http://some.domain.com/somesite/en/projecten/img/logo.png

结束: http://some.domain.com/somesite/web/projecten/img/logo.png/projecten/img/logo.png

虽然此时应该是: http://some.domain.com/somesite/web/projecten/img/logo.png

在日志中,我将问题追溯到trace3行,说明add path info postfix:,基本上会添加不需要的部分。该行直接位于执行第一次匹配重写之后。一切都在同一个处理过程中发生。

这是我唯一的两个链接规则,即不是最终结果,因此没有L - 标志。这似乎与问题有关。

有人可以告诉我正在发生的事情,原因和有效的解决方案吗?

提前致谢!

编辑: 记录与此请求相关的完整日志:

[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/en -> /home/dev/domains/dev.company.nl/public_html/company_website/en/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/en/projecten/img/company_logo.png -> en/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^(.*)$' to uri 'en/projecten/img/company_logo.png'
[rewrite:trace4] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] RewriteCond: input='/company_website/en/projecten/img/company_logo.png' pattern='!/(web|cms|shared)/.*$' => matched
[rewrite:trace2] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] rewrite 'en/projecten/img/company_logo.png' -> 'web/en/projecten/img/company_logo.png'
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add per-dir prefix: web/en/projecten/img/company_logo.png -> /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png -> /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/en/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^web/(en|nl)/(.*)$' to uri 'web/en/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace2] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] rewrite 'web/en/projecten/img/company_logo.png/projecten/img/company_logo.png' -> 'web/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add per-dir prefix: web/projecten/img/company_logo.png/projecten/img/company_logo.png -> /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace2] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] trying to replace prefix /home/dev/domains/dev.company.nl/public_html/company_website/ with /company_website/
[rewrite:trace5] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] strip matching prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace4] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] add subst prefix: web/projecten/img/company_logo.png/projecten/img/company_logo.png -> /company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace1] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] internal redirect with /company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png [INTERNAL REDIRECT]
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten -> /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^(.*)$' to uri 'web/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace4] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] RewriteCond: input='/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png' pattern='!/(web|cms|shared)/.*$' => not-matched
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten -> /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^web/(en|nl)/(.*)$' to uri 'web/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace1] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] pass through /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten

0 个答案:

没有答案