2012-03-24 37 views
1

我在所有的mod_rewrite不是專家,我想以下的條件添加到規則:現代重寫規則不匹配的某些詞語

  1. 匹配這不等於「份額」
  2. 不能以點在它

RewriteRule ^([^/]*)$ http://domain.com/directory/index.php?key=$1 [L]

http://domain.com/directory/share將不匹配(股)

匹配任何

http://domain.com/directory/foo.php不會匹配(包含一個圓點)

http://domain.com/directory/abcde將匹配

http://domain.com/directory/abcde-4將匹配

所有ULRs不會有結尾的斜線

任何幫助將大大讚賞

回答

1

通過將.添加到否定字符cla SS:

RewriteRule ^([^./]*)$ <snip> 

不匹配結束/share

RewriteRule ^([^/]*/share)$ <snip> 

結合他們不匹配或者使用一個negative lookahead

RewriteRule ^([^./])*(?!/share)$ <snip> 
+0

還是我只是做了三個規則? RewriteRule ^([^ /] *(?! share))$ http://domain.com/directory/index.php?key=$1 [L]' 'RewriteRule ^([^ /]) */share)$ http://domain.com/directory/index.php?key=$1 [L]' 'RewriteRule ^([^。/] *(?! share))$ http:// domain .com/directory/index.php?key = $ 1 [L]' – 2012-03-24 05:38:53

+0

我看到,它有點工作,但'key'總是'share' - 無論匹配的字符是什麼。動態url應該是http://domain.com/directory/index.php?key=abcde-3而不是http://domain.com/directory/index.php?key=share – 2012-03-24 05:47:48

+0

嘗試移動parens:' ^([!。/])*(?!/ share)$'(對不起,這只是一個猜測,但我已經睡了22個小時) – 2012-03-24 05:49:13