我剛開始使用Codeigniter開發一個使用本地服務器(MAMP)的簡單靜態網站。最初我訪問我的主頁的本地地址是http://localhost/index.php/home
。即使一個簡單的本地主機將重定向到我的主頁。我想從URL中刪除'index.php',因此我複製粘貼了我在網上找到的.htaccess代碼。該代碼看起來像以下:本地主機在codeigniter文件夾中添加.htaccess後直接指向www.domains.tld
<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://localhost/$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>
起初,我複製粘貼代碼,而不改變它在所有(這是我的一部分愚蠢的),所以在代碼中的「localhost」的上面最初「www.domains。 TLD」。當我在瀏覽器上運行本地主機時,它指向www.domains.tld'。我注意到了這個錯誤,並將其改爲上面的內容,localhost仍然指向'www.domains.tld'我刪除了.htaccess文件來扭轉效果,但它仍然執行相同的操作。 我也改變了我的根文件夾的本地主機,但無論我做本地主機指向'domains.tld'。當我在瀏覽器的地址欄中鍵入127.0.0.1時,它會正確導向我的網站。我花了數小時閱讀這種行爲的原因,但沒有找到解決辦法。
任何幫助將不勝感激。
感謝, H.
非常感謝...你救了我的一天!我在Mac上使用Firefox 15.0.1版本以及about:config,但沒有找到'network.dnsCacheEntries',也沒有找到'network.dnsCacheExpiration'。但是我確實發現'network.dns.disablePv6'被設置爲'false',我將其切換爲'true',這似乎解決了這個問題。 在Google chrome上,我無法在隱私設置中找到有關DNS預取選項的任何信息,但清空緩存並刪除cookie似乎可以解決問題(不確定是否是確切原因)。無論哪種方式,問題得到解決,我再次感謝你! – hrshd
默認情況下,首選項不存在,因此您必須創建它們。我會在我的回答中澄清。 – Brendan