Mod_rewrite只使用一些规则

时间:2011-09-19 16:38:07

标签: .htaccess mod-rewrite

我有这个htaccess:

RewriteEngine On
RewriteRule ^tuote\.php/([^/]+) tuote.php?data=$1 [L]
RewriteRule ^ryhma\.php/([^/]+) ryhma.php?data=$1 [L]

RewriteRule ostoskori ostoskori.php [L]
RewriteRule ^lisaa\/([^/]+) ostoskori.php?a=4&data=$1 [L,NC]
RewriteRule ^lisaa-ostoskoriin/([^/]+) ostoskori.php?a=1&data=$1 [L,NC]
RewriteRule tyhjenna-ostoskori ostoskori.php?a=2

RewriteRule ^vahenna\/([^/]+) ostoskori.php?a=3&data=$1 [L,NC]
RewriteRule ^poista\/([^/]+) ostoskori.php?a=5&data=$1 [L,NC]

当我访问lisaa-ostoskoriin时,它无效并且似乎连接ostoskori.php但它应该连接ostoskori.php?a=1&data=$1

当我访问tyhjenna-ostoskori时,它既不起作用也似乎连接ostoskori.php但它应该ostoskori.php?a=2

所有其他人都会工作,但这些只是不起作用。我应该如何修改代码以使其更好地工作?

网址示例
http://somesite.com/tuote/1-Product-name - > tuote.php?data=1-Product-name http://somesite.com/ryhma/1-Category-name - > ryhma.php?data=1-Category-name http://somesite.com/ostoskori - > ostoskori.php
http://somesite.com/lisaa/1-Product-name - > ostoskori.php?a=4&data=1-Product-name http://somesite.com/lisaa-ostoskoriin/1-Product-name - > ostoskori.php?a=1&data=1-Product-name

1 个答案:

答案 0 :(得分:1)

试试这个:

RewriteEngine On
RewriteRule ^/(tuote|ryhma)\.php/([^/]+) $1.php?data=$2 [L]

RewriteRule ^/lisaa-ostoskoriin/([^/]+) ostoskori.php?a=1&data=$1 [L,NC]
RewriteRule ^/tyhjenna-ostoskori ostoskori.php?a=2 [L]
RewriteRule ^/vahenna/([^/]+) ostoskori.php?a=3&data=$1 [L,NC]
RewriteRule ^/lisaa/([^/]+) ostoskori.php?a=4&data=$1 [L,NC]
RewriteRule ^/poista/([^/]+) ostoskori.php?a=5&data=$1 [L,NC]

RewriteRule ^/ostoskori ostoskori.php [L]

我自己没有测试过。但是顺序和正则表达式在这里非常重要,因为每次跟随匹配都会导致替换。