【问题标题】:I cannot get .htaccess rewrite rule to work with my Prestashop site我无法让 .htaccess 重写规则与我的 Prestashop 网站一起使用
【发布时间】:2015-03-25 11:55:06
【问题描述】:

好的,我使用自动生成器在 .htaccess 文件中为我的 prestashop 站点生成自定义 URL,但它不起作用。有什么想法吗?

原来的网址是:

http://www.example.com/de/suche?controller=search&orderby=position&orderway=desc&search_query=mutter&submit_search=OK

重写后的url应该是:

http://www.example.com/search/position/desc/mutter/OK.html

我在 .htaccess 文件中的重写规则是:

RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /de/suche?controller=$1&orderby=$2&orderway=$3&search_query=$4&submit_search=$5 [L]

【问题讨论】:

  • 您的规则看起来不错。定义“不工作”。是否启用了重写引擎? .htaccess 中的其他指令?
  • 嘿,谢谢,是的,重写引擎已打开,还有一堆其他指令(所有标准的 prestashop 东西)我的意思是“不工作”是一个 404 未找到错误而不是实际重定向。这有帮助吗?
  • 澄清一下,这是内部重写,而不是外部重定向,所以您实际上不会看到 地址栏中 URL 的任何更改 - 这是您所期望的吗?找不到的网址是什么?如果您想查看 URL 更改进行测试,可以通过添加 R 标志将其更改为临时重定向。
  • 您问题第一部分的答案是“是的,完全正确!”。澄清一下,我想要完成的是我的 prestashop 网站上有一个动态搜索查询的结果页面。我想为它分配一个静态页面。但是当我在htaccess文件中添加上述重写规则并输入静态url时,会抛出404错误。谢谢!
  • 只是一个更新:添加 R 标志使其工作!但它现在就像一个重定向......我可以“隐藏”重定向的地址吗?还是我弄错了,你怎么看...?

标签: .htaccess url url-rewriting rewrite prestashop


【解决方案1】:

您应该从规则中删除 [L] 标志。它会阻止应用任何其他规则,但您需要将此新路由传递给 Prestashop 调度程序。

<IfModule mod_rewrite.c>
    RewriteEngine on

    #Domain: test.example.com
    RewriteRule . - [E=REWRITEBASE:/]
    RewriteRule ^api$ api/ [L]
    RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
    # Images
    RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
    # [...]

# You need to put your condition here without the [L] flag
# And before the Dispatcher
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /de/suche?controller=$1&orderby=$2&orderway=$3&search_query=$4&submit_search=$5
# Your URL is then rewritten to Prestashop standard format
# and will be sent to the following Dispatcher.

    # Dispatcher
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>

【讨论】:

    猜你喜欢
    • 2014-02-17
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2016-10-13
    • 2014-11-22
    • 2017-01-15
    相关资源
    最近更新 更多