在CodeIgniter中从域名中删除www
问题描述:
这就是我在.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]
答
通常的基本网址为相同的域名。它也包含www。 您可以使用基础URL调用您的css,js和图像文件。 www是不是要调用这些文件的问题。
+1
是的,我编辑了config.php文件并添加了适当的基本URL。谢谢!! – Bart
答
使用以下规则: -
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;
希望它会帮助你:)
你的问题似乎不清楚... –
可能的重复http://stackoverflow.com/questions/12030990/codeigniter-htaccess-to-remove-index-php-and-www –
我没有看到www中.htaccess文件,为什么WWW显示出来? – Bart