【问题标题】:Need to remove www from site URL's for a site built in Kohana对于在 Kohana 中构建的站点,需要从站点 URL 中删除 www
【发布时间】:2012-03-14 12:46:39
【问题描述】:

我正在寻找正确的位置(区域)来放置我的代码 sn-p 以从 URL 中删除 WWW

该站点位于 Kohana 中,为删除“www”而编写的代码是:

$host_name = $_SERVER['HTTP_HOST']; // it stores the host name / domain name
$tmp_host = substr($host_name, 0, 3);

if($tmp_host == 'www')
{
    $host_name = substr($host_name, 4);
}

任何帮助将不胜感激

【问题讨论】:

  • 那根本不属于 PHP。 .htaccess 是要走的路
  • 或者在它到达网站之前在你的路由器中完成它。

标签: php web url-rewriting kohana


【解决方案1】:

这是你需要的:

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

输入您的网址而不是 example.com 另外,这与 Kohana 无关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 2023-03-21
    • 2012-04-05
    • 2012-07-19
    • 2019-05-27
    • 2012-11-14
    相关资源
    最近更新 更多