2016-02-12 59 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