2011-11-09 30 views
1

我的問題是:HTML5樣板的.htaccess重寫到index.php

,如果我在HTML5 Bilerplate

<IfModule mod_rewrite.c> 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule^index.php [L] 
</IfModule> 

.htaccess文件的底部添加以下代碼,這將所有REQUEST_URI發送到我的index.php,所以我可以處理它們,但會破壞上面已經定義的.htaccess文件中的一些規則嗎?如果它錯了,應該添加什麼?

回答

0

你上面貼的規則已經存在於HTML5樣板的的.htaccess(在標題# Built-in filename-based cache busting

# Uncomment to enable. 
# <IfModule mod_rewrite.c> 
# RewriteCond %{REQUEST_FILENAME} !-f 
# RewriteCond %{REQUEST_FILENAME} !-d 
# RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L] 
# </IfModule> 

您可以通過在每行開頭去掉「#」取消其註釋。 並更改5日線,讓您的規則的favicon.ico:

RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif|ico)$ $1.$3 [L] 

編輯:

<IfModule mod_rewrite.c> 
    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    RewriteRule^http://%1%{REQUEST_URI} [R=301,L] 
    RewriteCond %{REQUEST_FILENAME} !^(.+)\.(js|css|png|jpg|gif|ico)$ 
    RewriteRule ^(.*)$ index.php [NC] 
</IfModule> 
於將所有的請求到index.php,我已經以這種方式修改 # Suppress or force the "www." at the beginning of URLs根據規則

一般而言,您應該將自己的規則放在.htaccess文件的開始位置之前,而不是放在其他規則之後。

+0

謝謝你的答案,但也許我沒有寫得很好我的問題。 我的問題是將所有請求重定向到index.php,以便重寫url。 –

+0

請檢查我的編輯。 – Salman