2

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

这是生成的 .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/contact-usmysite.dev.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
4

1 回答 1

1

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

它匹配 a(.*)并通过,无需重写,并且由于/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需要重写 (to contact-form.php) 的请求都会失败,因为 Multiviews 之类的东西不会触及它。


我不知道为什么您有 HTTP 授权标头,但它使您的所有请求都通过而无需任何重写。您可以尝试删除它(至少出于测试目的)并关闭 htaccess 文件顶部的多视图:

Options -Multiviews

看看你的规则是否有效。

于 2012-08-27T17:40:25.600 回答