2014-09-22 31 views
0

我想知道如何在維護模板下安裝我的站點。它包含這個文件和文件夾的:使用Apache .htaccess設置「維護中」模板

  • 的index.html
  • 圖片(文件夾)
  • 工具(文件夾)

我用下面的代碼在我.htaccess文件重定向到index.html,但它只顯示html內容。

RewriteEngine on 
RewriteCond %{REQUEST_URI} !/index.html$ 
RewriteCond %{REMOTE_ADDR} !^123.123.123.123 
RewriteRule $ /index.html [R=302,L] 

如何將圖片和CSS放到其他文件夾中?

回答

2

試試這個:

RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_URI} !^/maintenance\.html$ 
RewriteCond %{REMOTE_ADDR} !=123.123.123.123 
RewriteRule ^(images|tools)($|/) - [L] 
RewriteRule ^(.*)$ /maintenance.html [NC,L,R=302] 

這將忽略images & tools目錄,但所有的內容重定向到/maintenance.html。我還調整了REQUEST_URI URL的格式以及REMOTE_ADDR支票。

+0

感謝您的快速回復@JakeGould,我嘗試了您的代碼,但收到「該頁面無法正確重定向」消息。此外,我已將maintenance.html更改爲index.html,因爲index.html是我想使用的。 – user3476977 2014-09-23 01:39:57

+0

@ user3476977這應該很好。我自己測試過。你應該像這樣通過'curl -I'來檢查你的請求的標題:'curl -I http:// my.great.website'然後調整'.htaccess'來正常工作。 – JakeGould 2014-09-23 01:43:30

+0

@ user3476977當別人幫助你時,在評論中增加另一個問題就會被壓制。盡我所能幫助你盡我所能。祝你好運,通過發佈一個新問題並允許別人來幫助你解決這個新問題。如果你發現我的答案有幫助,請記住投票。如果這是解決您的問題的答案,請務必將其檢查出來。謝謝。 – JakeGould 2014-09-23 03:04:16