【问题标题】:Remove www from domain in CodeIgniter在 CodeIgniter 中从域中删除 www
【发布时间】:2016-02-12 08:28:44
【问题描述】:

这是我的 .htaccess 文件中的内容,当我运行速度测试时,www 正在显示并且还显示在所有 URL 中,如果您知道什么问题,请提供帮助。

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]

【问题讨论】:

标签: php apache .htaccess codeigniter


【解决方案1】:

使用以下规则:-

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

在规则中写下你的域名

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

在 Codeigniter 中,您可以设置基本 url 如下

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

希望对你有帮助:)

【讨论】:

  • 我不想设置重定向,我只想在我的域前面没有 www。如果没有重定向,这可能吗?是否所有 CodeIgniter 应用都默认有 www?
  • 是的。您需要将 www 替换为 http。这样做没有错误的方法。
  • 抱歉,是别人先发的。不过感谢您的帮助。
  • 不用说对不起。唯一重要的是您的问题得到解决:)
【解决方案2】:

通常情况下,基本网址与您的域名相同。它也包含 www。 您可以使用基本 url 调用您的 css、js 和图像文件。 www 不是调用这些文件的问题。

【讨论】:

  • 是的,我编辑了 config.php 文件并添加了正确的基本 URL。谢谢!!
猜你喜欢
  • 2017-08-28
  • 2016-01-16
  • 2018-03-31
  • 2014-08-24
  • 2016-08-20
  • 1970-01-01
  • 2012-08-15
  • 2013-08-17
  • 2014-06-05
相关资源
最近更新 更多