好像 thinkPHP5 新版本 隐藏 index.php 隐藏 index.php 都写好了
public 隐藏
独立主机可以直接把根目录指向 public 下
虚拟主机可以把 public 下的 index.php 放到根目录
public 下原有 index.php
- // 定义应用目录
- define('APP_PATH', __DIR__ . '/../application/');
- // 加载框架引导文件
- require __DIR__ . '/../thinkphp/start.php';
放到根目录下的 index.php
- // 定义应用目录
- define('APP_PATH', __DIR__ . '/application/');
- // 加载框架引导文件
- require __DIR__ . '/thinkphp/start.php';
Apache 下隐藏 index.php
tp5 好像都给写好了. htaccess 文件 index.php 都给隐藏掉了
如果是 index.php 移到根目录了只需要把. htaccess 文件放到根目录下
其中代码
- <IfModule mod_rewrite.c>
- Options +FollowSymlinks -Multiviews
- RewriteEngine On
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
- </IfModule>
iis 下隐藏
有的主机后台有 URL Rewrite 直接写规则就可以了
没有直接在根目录创建 web.config
其中代码
- <?xml version="1.0" encoding="UTF-8"?>
- <configuration>
- <system.webServer>
- <rewrite>
- <rules>
- <rule name="WPurls" enabled="true" stopProcessing="true">
- <match url=".*" />
- <conditions logicalGrouping="MatchAll">
- <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
- <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
- </conditions>
- <action type="Rewrite" url="index.php/{R:0}" />
- </rule>
- </rules>
- </rewrite>
- <defaultDocument>
- <files>
- <clear />
- <add value="index.php" />
- <add value="index.html" />
- </files>
- </defaultDocument>
- </system.webServer>
- </configuration>
来源: http://www.bubuko.com/infodetail-2578514.html