我通过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-us 和 mysite.dev.com/my-account :< / p>
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
答案 0 :(得分: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
匹配(.*)
并且没有重写,并且由于/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
)的请求都会失败,因为像Multiviews这样的东西不会触及它。
我不知道为什么你有HTTP自动化标题,但是它会让你的所有请求都被传递而没有任何重写。您可以尝试删除它(至少用于测试目的)并关闭htaccess文件顶部的多视图:
Options -Multiviews
并查看您的规则是否有效。