开始伪静态后,如何禁止“/index.php/xxx/xxx”这样的路径

已经开启伪静态后,可以通过http://www.xxx.com/xxx/xxx”http://www.xxx.com/index.php/xxx/xxx”两种方式访问应用程序,但我不希望“/index.php/xxx/xxx”这样的路径存在,如果此网址一旦暴露,对SE来说会产生页面镜像问题,请问该如何配置?

下面是我的.htaccess:




RewriteEngine On


#不带www的访问全部转到www

RewriteCond %{HTTP_HOST} ^xxx.com

RewriteRule (.*) http://www.xxx.com/$1 [R=301,L]


#输入http://www.xxx.com/后显示cms系统的首页

RewriteRule ^$ /cms/index.php


#yii-framework的伪静态

RewriteCond %{REQUEST_FILENAME} !\.(js|ico|gif|jpg|png|css|js)$

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php




在你的/protected/config/main.php裡面,找到components->urlManager,

加上


'showScriptName'=>false,

這樣URL就不會出現index.php

@Joshua Tam,我也是这么配置的,但仍然可以手动在浏览器地址栏中输入http://www.xxx.com/index.php/xxx/xxx的方式访问。

我是想禁止这种访问方式。如果此url泄漏很容易出现页面镜像的问题。

没有朋友知道吗?

简单方法:把index.php改名为其他文件,例如i.php(其他人不容易猜到的名字),重定向则指向这个文件即可。