1

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

我想将此 URL 更改为更简单的内容,例如 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>

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

4

1 回答 1

0

这条规则:

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
于 2014-05-16T16:24:12.923 回答