模块重写来自PrestaShop生成器的规则


Module rewrite rules from PrestaShop generator

我通过PrestaShop.htaccess文件生成器生成了.htacccess文件。有些规则不能正常工作。

这是生成的.htaccess文件:

    <IfModule mod_rewrite.c>
    # URL rewriting module activation
    RewriteEngine on
    # URL rewriting rules
    RewriteRule ^api/?(.*)$ /webservice/dispatcher.php?url=$1 [QSA,L]
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    RewriteRule ^([a-z0-9]+)'-([a-z0-9]+)('-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1-$2$3.jpg [L]
    RewriteRule ^([0-9]+)'-([0-9]+)/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1-$2.jpg [L]
    RewriteRule ^([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$1$2.jpg [L]
    RewriteRule ^([0-9])([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$2/$1$2$3.jpg [L]
    RewriteRule ^([0-9])([0-9])([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg [L]
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg [L]
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg [L]
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg [L]
    RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$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])([0-9])('-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*'.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg [L]
    RewriteRule ^c/([0-9]+)('-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*'.jpg$ /img/c/$1$2.jpg [L]
    RewriteRule ^c/([a-zA-Z-]+)/[a-zA-Z0-9-]+'.jpg$ /img/c/$1.jpg [L]
    RewriteRule ^([0-9]+)('-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*'.jpg$ /img/c/$1$2.jpg [L]
    RewriteRule ^([0-9]+)'-[a-zA-Z0-9-]*'.html /product.php?id_product=$1 [QSA,L]
    RewriteRule ^[a-zA-Z0-9-]*/([0-9]+)'-[a-zA-Z0-9-]*'.html /product.php?id_product=$1 [QSA,L]
    RewriteRule ^([0-9]+)'-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+ /category.php?id_category=$1&noredirect=1 [QSA,L]
    RewriteRule ^([0-9]+)'-[a-zA-Z0-9-]* /category.php?id_category=$1 [QSA,L]
    RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*) /supplier.php?id_supplier=$1 [QSA,L]
    RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*) /manufacturer.php?id_manufacturer=$1 [QSA,L]
    RewriteRule ^content/([0-9]+)'-([a-zA-Z0-9-]*) /cms.php?id_cms=$1 [QSA,L]
    RewriteRule ^content/category/([0-9]+)'-([a-zA-Z0-9-]*) /cms.php?id_cms_category=$1 [QSA,L]
    RewriteRule ^page-not-found$ /404.php [QSA,L]
    RewriteRule ^address$ /address.php [QSA,L]
    RewriteRule ^addresses$ /addresses.php [QSA,L]
    RewriteRule ^authentication$ /authentication.php [QSA,L]
    RewriteRule ^best-sales$ /best-sales.php [QSA,L]
    RewriteRule ^cart$ /cart.php [QSA,L]
    RewriteRule ^contact-us$ /contact-form.php [QSA,L]
    RewriteRule ^discount$ /discount.php [QSA,L]
    RewriteRule ^guest-tracking$ /guest-tracking.php [QSA,L]
    RewriteRule ^order-history$ /history.php [QSA,L]
    RewriteRule ^identity$ /identity.php [QSA,L]
    RewriteRule ^manufacturers$ /manufacturer.php [QSA,L]
    RewriteRule ^my-account$ /my-account.php [QSA,L]
    RewriteRule ^new-products$ /new-products.php [QSA,L]
    RewriteRule ^order$ /order.php [QSA,L]
    RewriteRule ^order-follow$ /order-follow.php [QSA,L]
    RewriteRule ^quick-order$ /order-opc.php [QSA,L]
    RewriteRule ^order-slip$ /order-slip.php [QSA,L]
    RewriteRule ^password-recovery$ /password.php [QSA,L]
    RewriteRule ^prices-drop$ /prices-drop.php [QSA,L]
    RewriteRule ^search$ /search.php [QSA,L]
    RewriteRule ^sitemap$ /sitemap.php [QSA,L]
    RewriteRule ^stores$ /stores.php [QSA,L]
    RewriteRule ^supplier$ /supplier.php [QSA,L]
    </IfModule>
    # Catch 404 errors
    ErrorDocument 404 /404.php

例如,这个重写规则不起作用

    RewriteRule ^contact-us$ /contact-form.php [QSA,L]

这很好用:

    RewriteRule ^my-account$ /my-account.php [QSA,L]

这是在我尝试输入页面后生成的重写日志:mysite.dev.com/联系我们mysite.def.com/my account

    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c7e80a0/initial] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/contact-us -> contact-us
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c7e80a0/initial] (3) [perdir /srv/www/mysite/] applying pattern '^api/?(.*)$' to uri 'contact-us'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c7e80a0/initial] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/contact-us -> contact-us
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c7e80a0/initial] (3) [perdir /srv/www/mysite/] applying pattern '.*' to uri 'contact-us'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c7e80a0/initial] (1) [perdir /srv/www/mysite/] pass through /srv/www/mysite/contact-us
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e82b0/initial/redir#1] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/404.php -> 404.php
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e82b0/initial/redir#1] (3) [perdir /srv/www/mysite/] applying pattern '^api/?(.*)$' to uri '404.php'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e82b0/initial/redir#1] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/404.php -> 404.php
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e82b0/initial/redir#1] (3) [perdir /srv/www/mysite/] applying pattern '.*' to uri '404.php'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e82b0/initial/redir#1] (1) [perdir /srv/www/mysite/] pass through /srv/www/mysite/404.php
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8db0a0/initial] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/page-not-found -> page-not-found
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8db0a0/initial] (3) [perdir /srv/www/mysite/] applying pattern '^api/?(.*)$' to uri 'page-not-found'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8db0a0/initial] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/page-not-found -> page-not-found
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8db0a0/initial] (3) [perdir /srv/www/mysite/] applying pattern '.*' to uri 'page-not-found'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8db0a0/initial] (1) [perdir /srv/www/mysite/] pass through /srv/www/mysite/page-not-found
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e62b8/initial/redir#1] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/404.php -> 404.php
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e62b8/initial/redir#1] (3) [perdir /srv/www/mysite/] applying pattern '^api/?(.*)$' to uri '404.php'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e62b8/initial/redir#1] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/404.php -> 404.php
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e62b8/initial/redir#1] (3) [perdir /srv/www/mysite/] applying pattern '.*' to uri '404.php'
    127.0.0.1 - - [27/Aug/2012:13:47:50 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8e62b8/initial/redir#1] (1) [perdir /srv/www/mysite/] pass through /srv/www/mysite/404.php
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c86b0a0/subreq] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/my-account.php -> my-account.php
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c86b0a0/subreq] (3) [perdir /srv/www/mysite/] applying pattern '^api/?(.*)$' to uri 'my-account.php'
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c86b0a0/subreq] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/my-account.php -> my-account.php
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c86b0a0/subreq] (3) [perdir /srv/www/mysite/] applying pattern '.*' to uri 'my-account.php'
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c86b0a0/subreq] (1) [perdir /srv/www/mysite/] pass through /srv/www/mysite/my-account.php
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8dd0a0/initial] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/my-account.php -> my-account.php
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8dd0a0/initial] (3) [perdir /srv/www/mysite/] applying pattern '^api/?(.*)$' to uri 'my-account.php'
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8dd0a0/initial] (3) [perdir /srv/www/mysite/] strip per-dir prefix: /srv/www/mysite/my-account.php -> my-account.php
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8dd0a0/initial] (3) [perdir /srv/www/mysite/] applying pattern '.*' to uri 'my-account.php'
    127.0.0.1 - - [27/Aug/2012:13:47:55 +0200] [mysite.dev.com/sid#7f77a22d6b80][rid#7f779c8dd0a0/initial] (1) [perdir /srv/www/mysite/] pass through /srv/www/mysite/my-account.php

RewriteRule ^contact-us$ /contact-form.php [QSA,L]不工作的原因:

strip per-dir prefix: /srv/www/mysite/contact-us -> contact-us
applying pattern '.*' to uri 'contact-us'
pass through /srv/www/mysite/contact-us

它匹配一个(.*)并在不重写的情况下通过,由于/contact-us不存在,它触发了404。此规则导致传递:

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

RewriteRule ^my-account$ /my-account.php [QSA,L]工作的原因:

strip per-dir prefix: /srv/www/mysite/my-account.php -> my-account.php
applying pattern '^api/?(.*)$' to uri 'my-account.php'
strip per-dir prefix: /srv/www/mysite/my-account.php -> my-account.php
applying pattern '.*' to uri 'my-account.php'
pass through /srv/www/mysite/my-account.php

嗯。。。它不起作用。这条规则永远不会被应用。与/contact-us的请求完全相同,只是您会注意到,当您请求/my-account时,实际通过重写引擎(作为SUBREQUEST)的是/my-account.php。php扩展甚至在到达重写引擎之前就被添加到了末尾,作为SUB REQUEST。

这让我觉得你在某个地方打开了Multiviews,这使得所有的请求都是有效的,你所需要做的就是在末尾添加一个.php扩展,因为RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]规则会立即通过它。但是,当然,任何像contact-us这样需要重写(到contact-form.php)的请求都是失败的,因为像Multiview这样的东西不会触及它


我不知道为什么你有HTTP authotification头,但它使你的所有请求都能在没有任何重写的情况下通过。您可以尝试删除它(至少出于测试目的)并关闭htaccess文件顶部的多视图:

Options -Multiviews

看看你的规则是否有效。