2010-07-25 70 views
0

我有一個虛擬主機的設置是這樣的:定影的mod_rewrite和mod_alias中衝突

Alias /somedir /some/other/dir 

工作正常

不過,我需要設置mod_rewrite用於/ somedir(一個笨的應用程序,對此我想清潔的網址)。下面是來自維基笨位:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

通常,當mod_rewrite在子目錄改變RewriteBase用於匹配目錄的名稱就足以使其工作:

RewriteBase /somedir 

...但它似乎不適用於mod_alias(獲得404s)。有沒有解決這個問題的方法?

+0

附註:當包含模擬網址時,使用example.com作爲域名,這就是它的用途。我懷疑你是site.com的所有者:) – Wrikken 2010-07-25 19:07:14

+0

你在哪裏定義了你的'mod_rewrite'規則? – 2010-07-25 19:09:08

+0

@Wrikken ups ...我的壞,謝謝你糾正:)。 @Tim,位於別名目錄根目錄下的'.htaccess'文件中。我也嘗試在vhost配置文件中設置它們,具有相同的效果。 – Andrei 2010-07-25 19:34:34

回答

0

我的測試服務器上的以下工作,所以想這可能會解決您的問題..

在你的虛擬主機:

Alias /somedir /some/other/dir 

RewriteEngine On 

# I think these conditions should work correctly; the other ones shouldn't 
# because the alias has not been applied at this stage of processing yet 
RewriteCond /some/other/dir%{REQUEST_URI} !-d 
RewriteCond /some/other/dir%{REQUEST_URI} !-f 
# L is unnecessary in this context, but be sure to PT so mod_alias picks up 
# on the rewrite 
RewriteRule ^/somedir/(.*)$ /somedir/index.php/$1 [PT] 
+0

謝謝,但它仍然無法正常工作......我嘗試將它放在'.htaccess'中,在別名目錄的根目錄下,在vhost配置中的一個''塊中,仍然沒有。 – Andrei 2010-07-26 10:58:50

+0

您是否嘗試將它放在任何''/''塊以外的虛擬主機配置中?稍後我會用'.htaccess'進行測試,看看我能否弄清楚爲什麼這可能不起作用。 – 2010-07-26 17:19:23

0

雖然我沒有測試你的樣品,在我自己的配置,我並沒有在PT標誌上取得太多成功,這可能是因爲我在配置中與重寫規則的交互。

我發現限制使用別名到重寫條件更容易,並且總是在重寫輸出中使用文件系統路徑。

Define SOME_DIR = "/somedir" 
Define SOME_OTHER_PATH = "/some/other/dir" 

Alias "${SOME_DIR}" "${SOME_OTHER_PATH}" 

RewriteEngine On 
RewriteCond ${SOME_DIR}%{REQUEST_URI} !-d 
RewriteCond ${SOME_DIR}%{REQUEST_URI} !-f 

RewriteRule ^${SOME_DIR}/(.*)$ ${SOME_OTHER_PATH}/index.php/$1 [NC,QSA,L]