我使用RewriteRule将URL中的所有空格(又名%20)替换为下划线:
RewriteRule (.*)[\ ](.*) $1_$2 [N]N标志再次启动重写过程,直到没有空间(希望如此)。现在,当另一边有一个文件在等待,即请求时,一切都很好:
/This is an example.html和档案:
This_is_an_example.html但是,当没有匹配的文件时,Apache退出时会出现500个内部错误。错误日志声明一个分段错误,重写日志显示重写引擎试图重定向到的疯狂状态。
/This is an_example.html/This is an_example.html/This is an_example.html/...以此类推,直到分段错误(注意,最后一个空格被转换,但没有其他)。
有谁想过,为什么RewriteRule在处理现有文件时失败得如此糟糕?
更新:只有在请求的URI中存在额外的"/“时才会发生分段错误,如
/virtual-directory/This is an example.html更新2:该语句中没有RewriteCond。在我看来,它应该在没有。问题是为什么不。Htaccess:
RewriteEngine On
RewriteBase /test/
RewriteRule (.*)[\ ](.*) $1_$2 [N]更新3:所讨论的.htaccess文件:
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的数据填充到文件中。这是摘要:
(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行:“添加路径信息后缀”。
发布于 2009-11-20 06:51:39
更新
看看你的更新3(很有帮助,谢谢),我又想到了两个点子:
RewriteRule中:
RewriteRule (.*)\ $1_$2 N,DPI
看看能不能解决这个问题。需要apache 2.2.12。DirectorySlashOn?试着禁用它。更新端
你的设置:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} .*[\ ].*
RewriteRule (.*)[\ ](.*) $1_$2 [N]为我工作(http://localhost/test/This is an example.html,重写VirtualHost配置中的规则,Apache2.2.14)。这是我的RewriteLog (使用RewriteLogLevel 2):
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等)吗?在你的网址上也有用吗?
发布于 2009-11-05 13:13:37
尝试一个绝对的替代:
RewriteRule ^([^\ ]*)\ (.*) /$1_$2 [N]发布于 2009-11-22 18:39:17
总的来说,如果提供了一个可重复的测试用例,Apache开发人员将非常认真地对待httpd中的SIGSEGV。如果附加调试器并捕获回溯跟踪,情况就更糟了。
https://stackoverflow.com/questions/1680455
复制相似问题