2012-06-02 17 views
0

目前,我有規則重寫規則/的RewriteCond幫助 - 除了一個目錄匹配任何

RewriteRule ^([A-Za-z0-9-/]+)$ myFile.php?myId=$1 

我希望能夠訪問一個文件夾,它的文件(讓剛剛說這就是所謂的例子),而索引它的.php。但是,使用規則

RewriteRule ^example$ example/index.php [L] 

它改爲匹配第一條規則。不過,這是該文件的第一條規則。

回答

1

你重寫規則執行後,example URL改寫爲example/index.php,然後重新進入重寫過程(在[L]標誌不阻止)。然後,您的其他重寫規則匹配。

因此,您必須爲example/index.php添加例外。例如:

RewriteRule ^example/index.php$ - [L] 

終止第二次重寫運行。確保將其插入到其他規則的上方。

0

你可以使用一個條件:

RewriteCond %{REQUEST_URI} !^/example 
RewriteRule ^([A-Za-z0-9-/]+)$ myFile.php?myId=$1 [L] 

這樣你會得到你的規則匹配,除非請求以「/例如」開頭。您可以添加額外的斜線,即'/ example /'以避免不匹配'/ example-page'。

+0

好主意,但它並不完全解決問題,因爲'/ example'應該被重寫爲'/ example/index.php' – user123444555621

+0

您可以將它與[DirectoryIndex](http://httpd.apache .ORG /文檔/ 2.0/MOD/mod_dir.html)? –