【问题标题】:redirect non www to www with .htaccess in yii在 yii 中使用 .htaccess 将非 www 重定向到 www
【发布时间】:2014-12-09 06:34:42
【问题描述】:

这是我的 .htacess :

Options +FollowSymLinks 
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

我想将非 www 请求重定向到 www.example.com 但是当我添加时

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

我的 css 和 js 以及其他文件现在出现 404 错误,所有文件请求都转到 yii 控制器

框架:yii2

PHP 5.4

阿帕奇:2.4.7

【问题讨论】:

    标签: php apache http yii


    【解决方案1】:

    我找到了这个答案:

    RewriteEngine on
    
    #non-www to www
    RewriteCond %{HTTP_HOST} ^adnasor\.ir 
    RewriteRule (.*) http://www.adnasor.ir/$1 [R=301,L]
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # otherwise forward it to index.php
    RewriteRule . index.php 
    

    【讨论】:

      猜你喜欢
      • 2012-10-19
      • 1970-01-01
      • 2012-11-16
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-12
      • 2015-12-31
      相关资源
      最近更新 更多