【问题标题】:Magento htaccess 301 RedirectsMagento htaccess 301 重定向
【发布时间】:2011-04-08 00:38:08
【问题描述】:

我们正在尝试启动一个 Magento 网站。我们进行了一大堆 URL 重写,但是当我将其添加到 .htaccess 文件时,该站点无法加载。

显然我做错了什么,这是我正在使用的代码:

RewriteCond %{QUERY_STRING} ^StoreLevel=3&PrevStoreLevel=1&productid=6067&Level1=155&p=5&term=&BrowseBy=0$
RewriteRule ^store\.php$ http://oursite.com/zproduct.html? [R=301,L]

非常感谢任何建议。

【问题讨论】:

  • 您收到了哪些错误消息?
  • 嘿,是的,这可能是有用的信息,我得到:500 Internal Server Error
  • 开启重写错误日志并发布你得到的输出。 RewriteLog /var/log/httpd/rewrite.log RewriteLogLevel 9
  • 试过了,粘贴在文件顶部:############################## ############ RewriteLog /var/log/httpd/rewrite.log RewriteLogLevel 9 ####################### ###################服务器在此踢回500错误
  • 你是把它放在 vhost conf 中吗? httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritelog

标签: .htaccess magento


【解决方案1】:

是否启用了 mod_rewrite?您可以使用一些条件使 .htaccess 文件更加防弹,如下所示:

<IfModule mod_rewrite.c>
    RewriteCond %{QUERY_STRING} ^StoreLevel=3&PrevStoreLevel=1&productid=6067&Level1=155&p=5&term=&BrowseBy=0$
    RewriteRule ^store\.php$ zproduct.html [R=301,L]
</IfModule>

另请注意,如果您的重定向保留在同一个域中,则无需输入完整的 URL。

顺便说一句,如果您只是进行基本的字符串匹配,那么使用正则表达式是没有意义的。有一个 page on the Apache wiki 简要概述了使用正则表达式的替代方法,您可能想要类似的内容:

RewriteCond %{QUERY_STRING} =StoreLevel=3&PrevStoreLevel=1&productid=6067&Level1=155&p=5&term=&BrowseBy=0

【讨论】:

  • 谢谢!这解决了我的问题,使用完整的 URL 似乎也引起了问题。现在关于更有效地格式化这些,我们有大约 1000 个,所以我们这样做是关键。你觉得这合适吗? RewriteCond %{QUERY_STRING} =Store.php?StoreLevel=3&PrevStoreLevel=1&productid=6067&Level1=155&p=5&term=&BrowseBy=0 RewriteRule zproduct.html [R=301,L]
  • 不,QUERY_STRING 只包含要匹配的查询字符串,所以您应该省略 Store.php?来自 RewriteCond。否则对我来说看起来不错。如果我的回答解决了你的问题,请采纳! ;)
猜你喜欢
  • 2014-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-01
  • 2011-01-03
  • 2012-03-10
  • 2021-07-22
  • 1970-01-01
相关资源
最近更新 更多