嘿,我在我们的一台机器上遇到了Apache mod_rewrite的configuration问题。 有没有人遇到/克服任何这些问题。
URL1( http://www.uppereast.com )没有被redirect到URL2( http://www.nyclocalliving.com )。 这肯定在我的testing环境中本地主机地址被重写为URL2(RewriteRule ^ http://upe.localhost $ http://www.nyclocalliving.com )。
我试图让所有的redirect规则工作(2200 +),但如果我使用更多的1000或更多的规则,“ http://www.nyclocalliving.com ”网站遇到服务器错误。
A).htaccess文件 – 我尝试了在本地环境中工作的最简单的方法
75 # Various rewrite rules. 76 <IfModule mod_rewrite.c> 77 RewriteEngine on 78 79 # BEGIN new URL Mapping rules 80 #RewriteRule ^http://www.uppereast.com/$ http://www.nyclocalliving.com ... 2307 #RewriteRule ^http://www.uppereast.com/zipcodechange.html$ http://www.nyclocalliving.com/zip-code-change
图。 1
B)/ var / log / httpd / error_log文件 – 有这些seg。 当我启用第一条规则(第80行)时出现故障错误。 否则没有错误日志。
1893 [Fri Sep 25 17:53:46 2009] [notice] Digest: generating secret for digest authentication ... 1894 [Fri Sep 25 17:53:46 2009] [notice] Digest: done 1895 [Fri Sep 25 17:53:46 2009] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations 1896 [Fri Sep 25 17:53:47 2009] [notice] child pid 29774 exit signal Segmentation fault (11) 1897 [Fri Sep 25 17:53:47 2009] [notice] child pid 29775 exit signal Segmentation fault (11) 1898 [Fri Sep 25 17:53:47 2009] [notice] child pid 29776 exit signal Segmentation fault (11) 1899 [Fri Sep 25 17:53:47 2009] [notice] child pid 29777 exit signal Segmentation fault (11) 1900 [Fri Sep 25 17:53:47 2009] [notice] child pid 29778 exit signal Segmentation fault (11) 1901 [Fri Sep 25 17:53:47 2009] [notice] child pid 29779 exit signal Segmentation fault (11)
图。 2
C)来自shell的更多debugging信息; mod_rewrite打开,这是机器的体系结构
1 # apachectl -t -D DUMP_MODULES | more 2 Loaded Modules: 3 core_module (static) 4 ... 5 rewrite_module (shared) 1 # uname -a 2 Linux RegionalWeb 2.6.24-23-xen #1 SMP Mon Jan 26 03:09:12 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux
图。 3
我看了一些以前的post( .htaccess不工作(mod_rewrite) ),但没有find一个解决scheme。 我确定有一个小的开关,我失踪了。
先谢谢Tim
我们从你的apacheconfiguration开始。 如果你在mod_rewrite规则开始的时候出现段错误,那么东西不是正确的。 你运行的是RPM / DEB版本的Apache吗? 还是你自己编译的东西?
在查看任何与您的语法有关的问题之前,我会先解决这个错误,尤其是因为它在您的本地主机上工作。
我不知道为什么它会segfault,但是,我认为你想要一个像这样的规则:
RewriteRule ^zipcodechange.html$ http://www.nyclocalliving.com/zip-code-change [R=301,L] RewriteRule ^(.*)$ http://www.nyclocalliving.com/$1 [R=301,L]
第一个规则将特别写入页面到新创build的页面,并做301redirect。 第二个规则将采取任何url请求,并将其redirect到其他网站与URL的页面部分不变。 如果您在页面上有参数(如pagename.html?something = else),请使用[R = 301,QSA,L]
RewriteRule ^ http://www.uppereast.com/ $ http://www.nyclocalliving.com
主机名/ URL在此时不可用。 我不知道在规则中会有什么问题导致它出现段错误,但是我认为上面的两个规则是按照你的意图做的。 至于段错误,这是一个单独的问题。
如果build议的规则起作用,我认为mod_rewriteparsing引擎中的某些内容必须与//有关。 如果上述规则仍然导致段错误,你可能想要确保你的apache模块和基本版本匹配。 也许你重新编译了预先包装的apache之上的apache,你的编译选项并没有把这些模块放在同一个地方。
对于超过1000个规则的问题,除非在其中一个子目录中有.htaccess文件,并且它不包含Inherit语句,否则Apache必须读取当前目录或下面的所有文件的.htaccess文件。 每次必须为页面/资产提供服务时,可能会读取一个70k文件,这会导致内存分配超出限制。 你可以把这些规则放在你的apacheconfiguration中。
如果你需要基于servername / hostname来控制你的规则,你可以写规则
# simple and not really useful RewriteCond %{HTTP_HOST} ^domain\.com RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] # more useful RewriteCond %{HTTP_HOST} domainA\.com RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L] # or with a more specific match RewriteCond %{HTTP_HOST} domainA\.com RewriteRule ^zipcodechange.html$ http://www.domainB.com/zip-code-change [R=301,L]
还要确保你的“catchall”规则在所有特定规则的末尾…… ,L
选项表示最后的规则,这意味着.htaccess的其余部分被忽略(至less对于rewite)。