我有一个htaccess文件,开始如下所示:
RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} where-can-i-find-information-about-homer-training RewriteRule ^(.*)$ http://usersupport.homerenergy.com/customer/en/portal/articles/2186858-where-can-i-find-information-about-homer-training-? [R=301,L] RewriteCond %{QUERY_STRING} is-homer-pro-conservative-in-its-predictions RewriteRule ^(.*)$ http://usersupport.homerenergy.com/customer/en/portal/articles/2186859-is-homer-pro-conservative-in-its-predictions-? [R=301,L] ...
继续执行308条更类似的规则。 如您所见,这意味着将一列文章从一个网站redirect到另一个网站,其中匹配元素是GETstring的查询部分中的文章名称。
如果我只是在文件中放入一对或两对RewriteCond / RewriteRule ,这是RewriteRule的。 但是,当我使用整个文件,我得到一个500内部服务器错误。
显然,其中一个规则是导致错误,但扫描文件,我不明白这是什么。
看看错误日志,我可以看到这样的消息:
/var/www/html/.htaccess: RewriteCond: bad argument line '%{QUERY_STRING}'
这并没有告诉我很多。
我怎么知道哪个规则导致这个错误?
我相信你需要把你的testing值如下所示:
https://httpd.apache.org/docs/trunk/rewrite/remapping.html(section :重写查询string)
RewriteCond "%{QUERY_STRING}" "where-can-i-find-information-about-homer-training" RewriteRule "^(.*)$" "http://usersupport.homerenergy.com/customer/en/portal/articles/2186858-where-can-i-find-information-about-homer-training-?" [R=301,L]
你可能有一个空间,我猜你的价值观之一。 试着开始,可能会修复它。 我通常不使用“重写,但我也不通常使用空格,以及我的意思是,我从来没有使用这些types的名称空间。
就像旁边一样,
^(.*)$
没有任何意义,因为
(.*)
已经意味着:全部。 所以,我相信所有的开始和结束都是有点冗余的。
一个可能的替代错误是,你只是错过了一系列500的换行符,可能会仔细检查在你的代码编辑器中使用行号视图。