Apache伪静态配置:
1. 打开httpd.conf, 去掉
LoadModule rewrite_module modules/mod_rewrite.so
前面的注释#。
2. 修改网站根目录的.htaccess文件:
<IfModule mod_rewrite.c> Options +FollowSymLinks IndexIgnore */* # 开启rewrite模块 RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # 定向到index.php RewriteRule . index.php # 设置不能执行php权限的目录 RewriteRule assets/(.*).(php)$ – [F] RewriteRule framework/(.*).(php)$ – [F] RewriteRule requirements/(.*).(php)$ – [F] RewriteRule public/(.*).(php)$ – [F] RewriteRule themes/(.*).(php)$ – [F] RewriteRule uploads/(.*).(php)$ – [F] # 设置环境限制 #php_value upload_max_filesize 50M #php_value post_max_size 60M #php_value max_execution_time 2000 </IfModule> <IfModule mod_expires.c> # Activate mod_expires for this directory ExpiresActive on # locally cache common image types for 7 days ExpiresByType image/jpg "access plus 7 days" ExpiresByType image/jpeg "access plus 7 days" ExpiresByType image/gif "access plus 7 days" ExpiresByType image/png "access plus 7 days" # cache CSS files for 24 hours ExpiresByType text/css "access plus 24 hours" </IfModule>
3. 修改protected/config/main.php文件:
'urlManager'=>array( //'urlFormat'=>'path', 'showScriptName'=>false, //'urlSuffix'=>'.htm', 'rules'=>array( 'sitemap\.xml' => 'site/sitemap', //网站地图 'sitemap\.xsl' => 'site/sitemapxsl', //网站索引 'page/<id:\w+>'=>'page/index', //单页 '<controller:\w+>/<action:\w+>/cat_<catalog_id:\d+>/page_<page:\d+>'=>'<controller>/<action>', //分页 '<controller:\w+>/<action:\w+>/page_<page:\d+>'=>'<controller>/<action>', //分页 '<controller:\w+>/<action:\w+>/cat_<catalog_id:\d+>' => '<controller>/<action>', //内容列表 'tag/index/<tag:\w+>' => 'tag/index', //标签搜索页 '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ),
Nginx伪静态设置
1. 修改nginx.conf文件:
location / { if (!-e $request_filename){ rewrite ^/(.*) /index.php last; } }
2. 同上3
这样访问路径就是path形式的。