mod_rewrite .htaccess删除部分url prestashop博客

时间:2014-05-16 16:19:48

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

我的prestashop网站上有一个博客模块。以下是帖子的示例网址: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>

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

1 个答案:

答案 0 :(得分: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