2012-01-29 61 views
0

我有這個.htaccess這個重寫規則有什麼問題?

RewriteEngine On 
RewriteRule ^!/(.*)$ path/to/a/file/$1 [L] 
RewriteRule ^(.*)$ path/to/another/file/$1 [L] 

我想在www.website.com/!/this/形式的URL改寫爲path/to/a/file。任何與該模式不匹配的網址都應重寫爲path/to/another/file/

這裏就是我試圖遠:

RewriteEngine On 
RewriteRule ^!/(.*)$ path/to/a/file/$1 [L] 
RewriteCond ... 
RewriteRule ^(.*)$ path/to/another/file/$1 [L] 

當使用上述重寫規則,我得到一個500 - 內部錯誤。

我該如何解決?

+0

是什麼:'的RewriteCond ...'? – 2012-01-29 22:45:56

+0

@BookOfZeus,http://wiki.apache.org/httpd/RewriteCond – Shoe 2012-01-29 23:03:08

+0

IIRC!不是有效的URI字符。這將導致mod_rewrite在這個模式中陷入困境。 – TerryE 2012-01-30 00:01:43

回答

3

試試這個:

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_URI} ^/! 
RewriteRule ^!/([a-z0-9_\-\.]+) user/public/$1 [L] 
RewriteCond %{REQUEST_URI} !^/! 
RewriteRule ^([a-z0-9_\-\.]+)/([a-z0-9_\-\.]+)/?$ $1/controller/front.php/$2 [L] 
RewriteCond %{REQUEST_URI} !^/! 
RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/([a-z0-9_\-]+)/?$ $1/controller/front.php/$2/$3 [L] 
+0

我不知道這是一個例子,我根據你的問題回答了我的答案。在我更新我的答案之前,請告訴我,如果它是動態的,可以給我示例,那麼'path/to ...'的規則是什麼?謝謝 – 2012-01-30 23:01:17

+0

我更新了我的回答 – 2012-02-01 00:36:38

+0

現在我得到了404。另外,我必須指定'to/public /'和'controller/front.php /'相對於包含'.htaccess'的路徑而不是根目錄'RewriteBase /')。 – Shoe 2012-02-01 07:51:43