
<name>和<id> 后台自己定义内容
例:域名/detail-xxxx-23
xxxx 从数据库调取数据
这种效果单凭用thinkphp的配置是实现不了的,要想实现首先应该考虑隐藏入口文件。以下是几种环境下的配置:
apache:
1.httpd.conf配置文件中加载了mod_rewrite.so模块 //在APACHE里面去配置
#LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉
2.AllowOverride None 讲None改为 All //在APACHE里面去配置
<Directory "D:/server/apache/cgi-bin">
AllowOverride none 改 AllowOverride ALL
Options None
Order allow,deny
Allow from all
</Directory>
3.确保URL_MODEL设置为2,
在项目的配置文件里加入
return Array(
// .....
'URL_MODEL' =>'2',
// .....
)
4 .htaccess文件必须放到跟目录下
这个文件里面加:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
补充:在windows下不能建立以点开头的文件,你可以先随便建立一个文件
然后在DOS在 *** 作 rename xxxx.xxxx .htaccess
IIS环境:
如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:
RewriteRule (.*)$ /index\.php\?s=$1 [I]
在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:
<rewrite>
<rules>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
Nginx环境:
在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:
location / { // …..省略部分代码
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last
break
}
}
其实内部是转发到了ThinkPHP提供的兼容模式的URL,利用这种方式,可以解决其他不支持PATHINFO的WEB服务器环境。
如果你的ThinkPHP安装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。
location /youdomain/ {
if (!-e $request_filename){
rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last
}
}
静态路由:指的是路由是固定的,是在配置文件里面固定好的。动态路由:路由带有参数或者使用正则表达式进行匹配。
两者都是在配置文件中进行设置,最大的区别就是静态路由是固定的,一条路由规则匹配一条url,而动态路由就是一条路由匹配多多条url,简单来说。静态路由是一对一,动态路由是一对多。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)