2011-05-09 30 views
2

我不知道爲什麼我的代碼不起作用。 我要到www添加到URL,當他們進入http://domain.co.uk/index.php 它將成爲http://www.domain.co.uk/只有 這裏我htaccess的代碼:在你的.htaccess文件.htaccess問題將www添加到url並刪除index.php

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^domain.co.uk [NC] 
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [L,R=301] 
RewriteRule index\.php http://www.domain.co.uk/ [NC,R] 
</IfModule> 
+0

你是什麼意思 「不工作」?它是否將您重定向到錯誤的地方?其他一些錯誤?更加詳細一些。 – hammar 2011-05-09 17:15:03

+0

網址不變。那是什麼情況 – gfivehost 2011-05-09 17:16:29

+0

我只知道,它是一個宙斯服務器。這是我第一次聽說有關宙斯重寫腳本。謝謝 – gfivehost 2011-08-13 13:02:43

回答

1

一些小的修正:

RewriteCond %{HTTP_HOST} ^domain\.co\.uk$ [NC] 
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [L,R=301] 

RewriteRule ^index\.php/?$ http://www.domain.co.uk/ [NC,R,L] 
  • .需要的條件進行轉義否則將匹配任何字符
  • 馬克每個單獨的規則在去年通過放置L
  • 附上條件^$標記開始和匹配
0

末在任何情況下,仍需要一個答案。使用另一個.htaccess。從這裏得到指導,我發現它和它看起來不錯:http://www.farinspace.com/codeigniter-htaccess-file/

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase/

    ### Canonicalize codeigniter URLs 

    # If your default controller is something other than 
    # "welcome" you should probably change this 
    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$/[L,R=301] 
    RewriteRule ^(.*)/index/?$ $1 [L,R=301] 

    # Removes trailing slashes (prevents SEO duplicate content issues) 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)/$ $1 [L,R=301] 

    # Enforce www 
    # If you have subdomains, you can add them to 
    # the list using the "|" (OR) regex operator 
    RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC] 
    RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301] 

    # Enforce NO www 
    #RewriteCond %{HTTP_HOST} ^www [NC] 
    #RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301] 

    ### 

    # Removes access to the system folder by users. 
    # Additionally this will allow you to create a System.php controller, 
    # previously this would not have been possible. 
    # 'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php/$1 [L] 

    # Checks to see if the user is attempting to access a valid file, 
    # such as an image or css document, if this isn't true it sends the 
    # request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 

</IfModule> 

<IfModule !mod_rewrite.c> 

    # Without mod_rewrite, route 404's to the front controller 
    ErrorDocument 404 /index.php 

</IfModule> 

記住,一旦你有你的CodeIgniter htaccess文件設置,你將要進入你的「/system/application/config/config.php 」,找到以下內容:

$config['index_page'] = "index.php"; 

並將其更改爲:

$config['index_page'] = ""; 
相關問題