Home > Backend Development > PHP Tutorial > 请教大神htaccess文件规则

请教大神htaccess文件规则

WBOY
Release: 2016-06-06 20:47:03
Original
1107 people have browsed it

需求有俩个。
1.http自动跳转https
2.index.php屏蔽掉,thinkphp框架。

Thanks

回复内容:

需求有俩个。
1.http自动跳转https
2.index.php屏蔽掉,thinkphp框架。

Thanks

建议查看相关文档。http://www.htaccesseditor.com/sc.shtml 这里提供一个可以在线生成的web。

补充:http://hi.baidu.com/honfei/item/0893a6e12984903a4ddcafbc

一,http直接跳转到https

<code class="lang-php">RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
</code>
Copy after login

二,TP屏蔽index.php
如果是Apache则需要在入口文件的同级添加.htaccess文件,内容如下:

<code class="lang-php"><ifmodule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</ifmodule>
</code>
Copy after login

Nginx环境
在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:

<code class="lang-php"> location / { // …..省略部分代码
   if (!-e $request_filename) {
   rewrite  ^(.*)$  /index.php?s=$1  last;
   break;
    }
 }
</code>
Copy after login

ThinkPHP手册上都会有说明,建议仔细看一下 : )

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template