【问题标题】:Prestashop - .htaccess URL Rewriting (add perso link)Prestashop - .htaccess URL 重写(添加个人链接)
【发布时间】:2022-01-23 22:06:25
【问题描述】:

我想知道为什么个人链接(用于 url 重写)不适用于 Prestashop...

我做了一个测试(在文件末尾添加):

RewriteRule ^test$ /index.php [L]

但它不起作用。我在网上搜索,但我没有找到任何东西...... Prestashop 的默认 URL 重写有效,但我无法添加其他链接

你能帮帮我吗?您需要更多信息吗?

谢谢

htaccess 文件:

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# Images
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]

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

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-javascript "access plus 1 week"
    ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

FileETag INode MTime Size
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

## Ajout manuelle ##
# RewriteRule ^kit-chaine-afam.htm$ /content/6-kit-chaine-afam [L]
RewriteRule ^www.accessoires-de-la-moto.com/kit-chaine-afam.htm$ /index.php?id_cms=6&controller=cms [L]
RewriteRule ^/test$ /index.php [L]
RewriteRule ^www.accessoires-de-la-moto.com/test2$ www.accessoires-de-la-moto.com/index.php [L]

RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
RewriteRule ^test3$ %{ENV:REWRITEBASE}index.php [L]

【问题讨论】:

  • 有什么解决办法吗?有的话分享一下

标签: .htaccess url-rewriting prestashop


【解决方案1】:

您是否在 htacces 文件中尝试过简单的“RedirectPermanent”?

    RedirectPermanent /old_page_urlp /new_page_url

有效吗?

【讨论】:

  • 我试过了:RedirectPermanent www.accessoires-de-la-moto.com/test89 www.accessoires-de-la-moto.com/index.php 但还是不行
【解决方案2】:

这两个

RewriteRule ^www.accessoires-de-la-moto.com/kit-chaine-afam.htm$ /index.php?id_cms=6&controller=cms [L]
RewriteRule ^www.accessoires-de-la-moto.com/test2$ www.accessoires-de-la-moto.com/index.php [L]

无法工作,因为域不是 URL 路径模式的一部分。

这条规则应该有效

RewriteRule ^/test$ /index.php [L]

但上面的这条规则来自 Prestashop

RewriteRule ^.*$ - [NC,L]

阻止它。

您可以将规则移到 Prestashop 定义之上

RewriteRule ^test$ /index.php [L]

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.accessoires-de-la-moto.com$
...

然后,/test 规则将按预期工作。但请注意不要干扰 Prentashop 的规则。

【讨论】:

  • 不,我做了其他测试,但还是不行。我用完整的代码 Htacess 更新了我的帖子
  • 感谢您的解释,但您可以看到仍然无法正常工作:accessoires-de-la-moto.com/test // 我应该删除“RewriteRule ^.*$ - [NC,L]”吗?
  • @Snow 这可能与前导或尾随斜杠有关,我将模式更改为^/?test/?$。请查看更新的答案。
  • @Snow 看来,我的浏览器中有一些重定向缓存问题。我更新了我的答案。
  • 我做到了,但它不起作用......也许我不能用 Prestashop 添加新规则?很奇怪,如果您需要更多信息,可以问我。
【解决方案3】:

您只需转到首选项-> SEO 和 URL。在设置 URL 部分,将友好 URL 切换为是。

【讨论】:

    【解决方案4】:

    您可以从管理面板更改 URL 重写配置和规则:

    首选项 -> SEO 和 URL -> URL 架构

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 2013-08-01
      • 1970-01-01
      相关资源
      最近更新 更多