【问题标题】:mod_rewrite .htaccess remove part of url prestashop blogmod_rewrite .htaccess 删除部分 url prestashop 博客
【发布时间】:2014-05-16 16:19:48
【问题描述】:

我的 prestashop 网站中有一个博客模块。这是帖子的示例 URL:mydomain/blog/aprender-idiomas-online/polonia-oportunidades-de-negocio

我想将此网址更改为更简单的网址,例如 mydomain/polonia-oportunidades-de-negocio 基本上从 URL 中删除这部分 /blog/aprender-idiomas-online

我已经尝试了一百万件事,但我无法让它发挥作用。我认为它应该在 .htaccess 中添加类似的东西,但它什么也没做..

    RewriteRule ^/blog/aprender-idiomas-online/(.*)$ /$1

这是我的 .htaccess,你可以看到它已经有一些重写规则,但我太新手了,无法完全理解它们。我已经在 RewriteEngine on

之后设置了我的规则
    <IfModule mod_rewrite.c>
    <IfModule mod_env.c>
    SetEnv HTTP_MOD_REWRITE On
    </IfModule>

    RewriteEngine on
    RewriteRule ^/blog/aprender-idiomas-online/(.*)$ /$1
    RewriteRule . - [E=REWRITEBASE:/]
    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]
    RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
    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]
    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]
    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]
    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]
    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]
    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]
    RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
    RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
    # AlphaImageLoader for IE and fancybox
    RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]

    # 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>

有人可以帮我吗?谢谢!!

【问题讨论】:

    标签: php apache .htaccess mod-rewrite prestashop-1.6


    【解决方案1】:

    这条规则:

    RewriteRule ^/blog/aprender-idiomas-online/(.*)$ /$1
    

    需要

    http://example.com/blog/apprender/idiomas-online/foo/bar/baz
    

    把它变成

    http://example.com/foo/bar/baz
    

    这可能不会存在于您的服务器上,从而导致 404 错误。

    应该重写为实际的脚本或文件,例如

    RewriteRule ^/blog/aprender-idiomas-online/(.*)$ /controller.php?path=$1
    

    会产生

    http://example.com/controller.php?path=foo/bar/baz
    

    【讨论】:

      猜你喜欢
      • 2012-02-26
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2018-06-10
      • 2017-07-04
      • 1970-01-01
      相关资源
      最近更新 更多