2010-03-08 56 views
3

我使用mod_rewrite和.htacces文件設置了一些簡單的url重寫規則,但是我遇到了一些問題。 如果我成立了.htacces這樣:mod_rewrite和相關網址

Options +FollowSymLinks 

RewriteEngine On 
RewriteBase/

RewriteRule /index.html /index.php [L] 

當我從瀏覽器中調用這個網址: http://localhost/~dave/mySite/index.html 我得到了一個404錯誤。

使用這種.htacces代替

Options +FollowSymLinks 

RewriteEngine On 
RewriteBase/

RewriteRule /index.html http://localhost/~dave/mySite/index.php [L] 

一切工作正常,我讓我期待的index.php頁面。 我是否被迫將用戶絕對URL作爲重寫的目標?這是一個Apache配置問題?

我使用Max OS X 10.6.2及其標準的Apache安裝。

+0

你想在哪裏使用.htaccess文件? – Gumbo

回答

4
  1. RewriteBase base指令設置基本路徑;您不需要在重定向規則中提供絕對路徑。

  2. 規則模式不是純文本;這是一個正則表達式。

  3. 如果您設置完整的URL作爲目標,則指示瀏覽器重定向到其他位置;這種重定向對用戶來說不透明。

綜上所述,試試這個來代替:

RewriteRule ^index\.html$ index.php [L] 
+0

刪除開始的斜槓解決了這個問題,謝謝! –

0

嘗試做

RewriteRule ^(.*)/index.html $1/index.php [L] 

這應該排序。