这里放下 几个关键点。有需要的 伙伴也可以借用了。
首先是 服务器安装配置 Rewrite 这个略去不提
重头戏是 Rewrite 规则的写法
[ISAPI_Rewrite]
# Defend your computer from some worm attacks
#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# 匹配文件后缀名
RewriteRule .*\.(?:gif|jpg|png|css|js|txt|jpeg|swf|flv|shtml|html) $0 [I,L]
# 不允许读取在文件后缀
RewriteRule /httpd(?:\.ini|\.parse\.errors) / [F,I,O]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 匹配目录根
RewriteRule ^\/$ $0\/index.php [L]
RewriteRule .*\/ $0\/index.html [L]
# 前台设置
RewriteRule ^(?!/index.php)(.*)$ /index.php/$1 [L] 另外应用配置中 增加以下配置 \common\conf\config.php 文件 //伪静态后缀
'URL_HTML_SUFFIX'=>'htm' ,
/* URL配置 */
'URL_CASE_INSENSITIVE' => true, //默认false 表示URL区分大小写 true则表示不区分大小写
'URL_MODEL' => 2, //URL模式 改写模式
'VAR_URL_PARAMS' => '', // PATHINFO URL参数变量
'URL_PATHINFO_DEPR' => '/', //PATHINFO URL分割符在根目录下增加一个 引导文件 index.html 仅仅是重定向功能,配置改写规则的寻找目录根下面的 index.html 用 (按上面的配置的话,这个文件可以不用了。)<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="1;url=/index.php" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>正在进入。。。,请稍等</title>
</head>
<body>
</body>
</html>简要解释:在重写URL的规则中,定义首先寻找 根下面的 index.html ,如果是 .html 文件直接输出,不用 index.php 解释。
使用新网站解释的部分,静态化为 后缀名 .htm 避免跟其他文件冲突。同时也保持了短路径。
访问网站 根域名,也是显示 http://域名/
已经完美的解决了 全部 index.php 的隐藏
也就是 http://域名/index.php/home/Controller/Action.htm 已经改写为了
http://域名/Controller/Action.htm ,对于SEO 是很友好的。
最佳答案