在整个项目目录中protected和themes文件夹下都有一个.htaccess,保证这两个文件夹不会被单独访问到
yii原始的url看来很复杂而且对seo并不友好
可以通过以下的配置来美化url
在protected/config/main.php中配置
1 'urlManager'=>array( 2 'urlFormat'=>'path', 3 'rules'=>array( 4 '<controller:w+>/<id:d+>'=>'<controller>/view', 5 '<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>', 6 '<controller:w+>/<action:w+>'=>'<controller>/<action>', 7 ), 8 'showScriptName'=>false, 9 'urlSuffix'=>'.html' //自定义后缀 10 ),
在入口文件的根目录下创建一个.htaccess文件(来自官网源码)
1 Options +FollowSymLinks 2 IndexIgnore */* 3 RewriteEngine on 4 5 # if a directory or a file exists, use it directly 6 RewriteCond %{REQUEST_FILENAME} !-f 7 RewriteCond %{REQUEST_FILENAME} !-d 8 9 # otherwise forward it to index.php 10 RewriteRule . index.php
如果xampp开启的虚拟主机,则修改apache/conf/extra/http-vhost.conf,增加
1 <VirtualHost *:80> 2 DocumentRoot "E:/yourwebroot" 3 ServerName yourwe.com 4 <Directory "E:/yourwebroot"> 5 Options Indexes MultiViews FollowSymLinks 6 AllowOverride All 7 Order allow,deny 8 Allow from all 9 </Directory> 10 </VirtualHost>
重启apache,即可以做到最简单的yii url rewrite