【问题标题】:Yii error when i try remove www prefix当我尝试删除 www 前缀时出现 Yii 错误
【发布时间】:2014-05-31 03:49:45
【问题描述】:

使用 .htaccess 我成功地从 url 中删除 index.php。 为了获得良好的 SEO 实践,我需要删除 WWW 前缀。组合两个 Apache 规则会出错。

我输入 www.site.com,我得到了 site.ru - 好的!

我输入 www.site.com/catalog,我得到了 site.ru - 错误!它的主页。

我输入 www.site.com/page/some_page,我得到了 site/index.php/some_page - 错误!

(注意:规则 'page/' => 'site/page', 'catalog/' => 'site/catalog/',)


.htaccess

RewriteEngine on
Options +FollowSymLinks


#redirect from WWW
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^/?(.*) http://%1/$1 [L,R=permanent]


#remove index.php from url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

【问题讨论】:

  • 我也遇到了这个问题...有人知道如何解决这个问题吗???

标签: .htaccess yii seo


【解决方案1】:

试试,

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

代替

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

希望对您有所帮助。

【讨论】:

  • 其他部分有问题。当我只离开 in.htaccess 时:#redirect from WWW RewriteCond %{HTTP_HOST} ^www\.(.*) [NC] RewriteRule ^/?(.*) http://%1/$1 [L,R=permanent ] 它的工作,但在 URL 中使用 index.php :(
  • 我希望你在配置'urlFormat'=>'path', 'showScriptName'=>false,
猜你喜欢
  • 2016-01-20
  • 1970-01-01
  • 2014-12-02
  • 2015-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-04
相关资源
最近更新 更多