2014-10-16 21 views
0

我想要做的URL與mod_rewrite的這樣的重寫URL:如何重寫在Apache的具體路徑參數

example.com/path/foo/rest_of_path-> example.com/path/rest_of_path (remove foo) 
example.com/path/bar/rest_of_path-> example.com/path/rest_of_path (remove bar) 
example.com/path/sample/rest_of_path-> no rewriting<br/> 
example.com/path/test/rest_of_path-> no rewriting 

酒吧是動態 測試樣品是靜態的,我有路徑列表。

所以我認爲做這樣的(在我的httpd.conf):

RewriteCond ....... #it's here i'm blocking, how write only if $1 in test,sample ? 
RewriteRule ^path/(.\*)/(.*)$ /path/$2 

回答

0
# You can add as much RewriteCond as you need to exclude static words 
RewriteCond %{REQUEST_URI} !^/path/sample/.* 
RewriteCond %{REQUEST_URI} !^/path/test/.* 
RewriteRule ^path/(.*)/(.*) /path/$2 
+0

謝謝 但它錯過[OR]標誌: 的RewriteCond%{REQUEST_URI}! ^/path/sample /.* [OR] RewriteCond%{REQUEST_URI}!^/path/test /.* – 2014-10-17 09:11:53

+0

不,您不需要[或]但是(隱含的)。只有在路徑中沒有靜態字樣和沒有靜態字測試的情況下,才需要應用RewriteRule。或者我誤解了你? – 2014-10-17 09:25:03

+0

是的,你說得對, 謝謝 – 2014-10-17 12:14:18