首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache: RewriteRule导致分段故障

Apache: RewriteRule导致分段故障
EN

Stack Overflow用户
提问于 2009-11-05 13:08:49
回答 3查看 1.7K关注 0票数 1

我使用RewriteRule将URL中的所有空格(又名%20)替换为下划线:

代码语言:javascript
复制
RewriteRule (.*)[\ ](.*) $1_$2 [N]

N标志再次启动重写过程,直到没有空间(希望如此)。现在,当另一边有一个文件在等待,即请求时,一切都很好:

代码语言:javascript
复制
/This is an example.html

和档案:

代码语言:javascript
复制
This_is_an_example.html

但是,当没有匹配的文件时,Apache退出时会出现500个内部错误。错误日志声明一个分段错误,重写日志显示重写引擎试图重定向到的疯狂状态。

代码语言:javascript
复制
/This is an_example.html/This is an_example.html/This is an_example.html/...

以此类推,直到分段错误(注意,最后一个空格被转换,但没有其他)。

有谁想过,为什么RewriteRule在处理现有文件时失败得如此糟糕?

更新:只有在请求的URI中存在额外的"/“时才会发生分段错误,如

代码语言:javascript
复制
/virtual-directory/This is an example.html

更新2:该语句中没有RewriteCond。在我看来,它应该在没有。问题是为什么不。Htaccess:

代码语言:javascript
复制
RewriteEngine On
RewriteBase /test/

RewriteRule (.*)[\ ](.*) $1_$2 [N]

更新3:所讨论的.htaccess文件:

代码语言:javascript
复制
AddType application/xhtml+xml .xhtml
AddEncoding x-gzip .gz

ExpiresActive On
ExpiresByType application/xhtml+xml "access plus 1 year"

ErrorDocument 404 /test/index.php?error=404

RewriteEngine On

RewriteBase /test/

# replace spaces with underscores
RewriteCond %{REQUEST_FILENAME} .*[\ ].*
RewriteRule (.*)[\ ](.*) $1_$2 [N]

# the index.php
RewriteRule ^index.php - [L]

# language tag
RewriteRule ^([a-z]{2})$ index.php?lang=$1&url= [L,QSA]
RewriteRule ^$ en [R=301,L]

# add .xhtml
RewriteCond %{REQUEST_FILENAME}.xhtml -s [OR]
RewriteCond %{REQUEST_FILENAME}.xhtml.gz -s
RewriteRule ^(.+) $1.xhtml

# add .gz
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz

# send correct mime type
#RewriteCond %{REQUEST_FILENAME} -s
RewriteRule \.xhtml\.gz$  - [L,T=application/xhtml+xml]

rewriteLog语句太大,无法粘贴。一个请求将13 of的数据填充到文件中。这是摘要:

代码语言:javascript
复制
(IP) - - [date] [host] (3) [perdir /htdocs/test/] add path info postfix: /htdocs/test/de -> /htdocs/test/de/This is a test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] strip per-dir prefix: /htdocs/test/de/This is a test -> de/This is a test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] applying pattern '(.*)[\ ](.*)' to uri 'de/This is a test'
(IP) - - [date] [host] (2) [perdir /htdocs/test/] rewrite 'de/This is a test' -> 'de/This is a_test'
(IP) - - [date] [host] (3) [perdir /htdocs/test/] add per-dir prefix: de/This is a_test -> /htdocs/test/de/This is a_test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] add path info postfix: /htdocs/test/de/This is a_test -> /htdocs/test/de/This is a_test/This is a test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] strip per-dir prefix: /htdocs/test/de/This is a_test/This is a test -> de/This is a_test/This is a test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] applying pattern '(.*)[\ ](.*)' to uri 'de/This is a_test/This is a test'
(IP) - - [date] [host] (2) [perdir /htdocs/test/] rewrite 'de/This is a_test/This is a test' -> 'de/This is a_test/This is a_test'
(IP) - - [date] [host] (3) [perdir /htdocs/test/] add per-dir prefix: de/This is a_test/This is a_test -> /htdocs/test/de/This is a_test/This is a_test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] add path info postfix: /htdocs/test/de/This is a_test/This is a_test -> /htdocs/test/de/This is a_test/This is a_test/This is a test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] strip per-dir prefix: /htdocs/test/de/This is a_test/This is a_test/This is a test -> de/This is a_test/This is a_test/This is a test
(IP) - - [date] [host] (3) [perdir /htdocs/test/] applying pattern '(.*)[\ ](.*)' to uri 'de/This is a_test/This is a_test/This is a test'
(IP) - - [date] [host] (2) [perdir /htdocs/test/] rewrite 'de/This is a_test/This is a_test/This is a test' -> 'de/This is a_test/This is a_test/This is a_test'
(IP) - - [date] [host] (3) [perdir /htdocs/test/] add per-dir prefix: de/This is a_test/This is a_test/This is a_test -> /htdocs/test/de/This is a_test/This is a_test/This is a_test
... and so on ad infinitum

坏蛋是第6行:“添加路径信息后缀”。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-11-20 06:51:39

更新

看看你的更新3(很有帮助,谢谢),我又想到了两个点子:

  1. 有一个apache问题:https://issues.apache.org/bugzilla/show_bug.cgi?id=38642,它看起来与您的类似。这是固定在2.2.12RewriteRule标志的引入。尝试将此标志添加到您的RewriteRule中: RewriteRule (.*)\ $1_$2 N,DPI 看看能不能解决这个问题。需要apache 2.2.12。
  2. 您是否碰巧启用了目录 DirectorySlashOn?试着禁用它。

更新端

你的设置:

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} .*[\ ].*
RewriteRule (.*)[\ ](.*) $1_$2 [N]

为我工作(http://localhost/test/This is an example.html,重写VirtualHost配置中的规则,Apache2.2.14)。这是我的RewriteLog (使用RewriteLogLevel 2):

代码语言:javascript
复制
init rewrite engine with requested uri /test/This is an example.html
rewrite '/test/This is an example.html' -> '/test/This is an_example.html'
rewrite '/test/This is an_example.html' -> '/test/This is_an_example.html'
rewrite '/test/This is_an_example.html' -> '/test/This_is_an_example.html'
local path result: /test/This_is_an_example.html
prefixed with document_root to D:/var/www/test/This_is_an_example.html
go-ahead with D:/var/www/test/This_is_an_example.html [OK]

D:/var/www/test/This_is_an_example.html不存在时,我得到一个404 -但没有分段错误。

你能把你的RewriteLog贴出来吗?你把重写规则放哪儿了?变成.htaccess?你有什么指令(AliasMatch等)吗?在你的网址上也有用吗?

票数 2
EN

Stack Overflow用户

发布于 2009-11-05 13:13:37

尝试一个绝对的替代:

代码语言:javascript
复制
RewriteRule ^([^\ ]*)\ (.*) /$1_$2 [N]
票数 0
EN

Stack Overflow用户

发布于 2009-11-22 18:39:17

总的来说,如果提供了一个可重复的测试用例,Apache开发人员将非常认真地对待httpd中的SIGSEGV。如果附加调试器并捕获回溯跟踪,情况就更糟了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1680455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档