【问题标题】:Traling Slash redirect for Prestashop CategoriesPrestashop 类别的尾随斜杠重定向
【发布时间】:2016-12-16 19:31:29
【问题描述】:

如何仅对 Prestashop 类别使用尾部斜杠 301 重定向 (!)?

我有这个解决方案,但这会强制所有 URL。

#Force trailing slash
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$

RewriteCond %{REQUEST_URI} !\.[^/]*$

RewriteRule ^(.*)$ /$1/ [L,R=301]

我对我的 URL 进行了重写。

Categories : {rewrite}/
Product: {category:/}{rewrite}.html

如果我使用一些没有斜线的类别,我需要这个来处理 404 错误:

http://shop.domain.com/category_example  -> 404 error

必须重定向到

http://shop.domain.com/category_example/

【问题讨论】:

    标签: .htaccess redirect prestashop prestashop-1.6


    【解决方案1】:

    在后台转到Preferences -> SEO & URLs 并将Route to category 设置为{id}-{rewrite:/}

    这将对类别使用尾部斜杠,并将不使用尾部斜杠的类别重定向到带有斜杠的正确 URL。

    【讨论】:

    • 你好,这个不行,因为根目录(index-php)变成了404错误。我的 URL 看起来也没有 ID:{rewrite}/
    • @user3221012 如果没有{id},你怎么能设置类别和产品路由? PrestaShop 不允许没有它的路由,至少不允许来自后台设置。但是,如果您正在使用一些 SEO 模块,那么您可能想向开发人员询问这一点。
    • 它使用 Dispachter 和 Link.php 覆盖。这对于 SEO 活动的友好 URL 很重要。
    • 我所有的 PS 项目都使用这个友好的 URL。无论如何,我现在尝试使用 htaccess 重定向
    【解决方案2】:

    尝试将以下代码添加到您的 .htaccess 文件中:

      # Various rewrite rules.
      <IfModule mod_rewrite.c>
      RewriteEngine on
    
      #--------------- custom redirects -----------------
      #hard coded  
      RewriteRule ^this_is_hot_news/index\.html http://www.mysite/news [R=301,L]
    
      RewriteRule (.*)/index\.html$ http://www.mysite.nl/$1 [R=301,L]
      RewriteRule (.*)\.html$ http://www.mysite.nl/$1 [R=301,L]
    
      RewriteRule (.*)/index\.php$ http://www.mysite.nl/$1 [R=301,L]
      RewriteRule (.*)\.php$ http://www.mysite.nl/$1 [R=301,L]
    
      #end custom redirects
    

    【讨论】:

      猜你喜欢
      • 2023-01-30
      • 1970-01-01
      • 2020-03-14
      • 2020-05-20
      • 2013-01-28
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多