2016-02-12 96 views
0

這就是我在.htaccess文件中的內容,當我運行速度測試時,www顯示並顯示在所有URL中,如果您知道哪些內容已損壞,請提供幫助。在CodeIgniter中從域名中刪除www

RewriteEngine On 
 

 
RewriteCond %{HTTPS} !=off 
 
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,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 
 
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css) 
 
RewriteRule ^(.*)$ index.php/$1 [L]

+0

你的問題似乎不清楚... –

+1

可能的重複http://stackoverflow.com/questions/12030990/codeigniter-htaccess-to-remove-index-php-and-www –

+0

我沒有看到www中.htaccess文件,爲什麼WWW顯示出來? – Bart

回答

0

通常的基本網址爲相同的域名。它也包含www。 您可以使用基礎URL調用您的css,js和圖像文件。 www是不是要調用這些文件的問題。

+1

是的,我編輯了config.php文件並添加了適當的基本URL。謝謝!! – Bart

1

使用以下規則: -

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

OR

在規則

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
RewriteRule (.*) http://example.com/$1 [R=301,L] 

寫你的域名在笨,您可以設置基本URL如下

$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST']; 
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); 
$config['base_url'] = $root; 

希望它會幫助你:)

+0

我不想設置重定向,我只是想要我的域沒有www infront。這可能沒有重定向?所有CodeIgniter應用程序默認都有www嗎? – Bart

+0

是的。您需要將www替換爲http。這樣做沒有錯誤的方法。 –

+0

重定向不好,他們在速度測試中傷害你。 – Bart