2013-10-18 105 views
1

在我.htaccess文件DirectoryIndex設置爲/page/main/home.html的.htaccess DirectoryIndex的網頁鏈接打破

因此,當我去www.thisexample.com瀏覽器的地址欄中顯示www.thisexample.com而實際加載www.thisexample.com/page/main/home.html。這一切都很好,但現在解決了這個問題:

任何.html無法找到鏈接到home.html的頁面。換句話說,當我點擊信息鏈接(在主頁上)時,它會查找www.thisexample.com/info.html(不存在),而不是在瀏覽器地址欄中顯示www.thisexample.com/info.html,但實際上正在加載www.thisexample.com/page/main/info.html(此處爲最終目標)。

這可能有助於補充說home.html沒有問題通過相對路徑找到它的CSS樣式表,只是找不到鏈接。

回答

0

DirectoryIndex應該是默認文件名像index.htmlindex.php爲前名:

DirectoryIndex index.html 

如果你想從/page/main加載所有的.html文件,然後有這些重寫規則:

DirectoryIndex home.html 

RewriteEngine On 

RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ [NC] 
RewriteRule !^page/main/ page/main%{REQUEST_URI} [L,NC] 

也開始在你的CSS,JS,圖像文件,而不是相對的使用絕對路徑。這意味着您必須確保這些文件的路徑始於http://或斜槓/

+0

我在'/ public_html'的'.htaccess'文件中添加了'RewriteRule!^ page/main// page/main%{REQUEST_URI} [L]'。我仍然有'DirectoryIndex/page/main/home.html',否則它只是把我帶到父目錄。鏈接仍然不起作用。你能澄清實施嗎? – user1345660

+0

如果您發現css,js,圖片鏈接被破壞,請在您的HTML頁面上嘗試''。 – anubhava

+0

你只需要'DirectoryIndex home.html' – anubhava