Yii ::重定向www.domain.com/index.php到www.domain.com而不使用htaccess

时间:2013-06-04 12:53:48

标签: php yii url-routing

我需要重定向

domain.com/index.php, www.domain.com/index.php & www.domain.com/index/ to www.domain.com

我的应用程序没有使用.htaccess文件。它必须只用PHP完成。

1 个答案:

答案 0 :(得分:4)

我认为没有.htaccess文件的解决方案,所以建立一个

在yii配置中,在组件:

处设置main.php
'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
     'caseSensitive'=>false,        
),

LoadModule rewrite_module modules / mod_rewrite.so

LoadModule rewrite_module modules / mod_rewrite.so

然后转到.htaccess文件,并尝试修改为:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

如果上述方法不起作用,请尝试使用此方法:

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

将.htaccess文件移动到根目录,其中index.php驻留。

WWW   - 受保护   - index.php   - .htaccess

重新启动服务器,然后一切正常