环境:phpStudy 2018/ThinkPHP5.0/php5.6.27/Apache
1.打开Apache配置文件httpd_conf
2.更改Apache服务器根目录:搜索DocumentRoot 将根目录设置成你的入口文件那个目录,例如DocumentRoot "X:\thinkphp5\public"
3.加载mod_rewrite.so :搜索mod_rewrite.so把这行前面的#去掉
4.搜索AllowOverride将 None 全部改为 All,如果Apache使用virtualhost 注意检查httpd-vhosts.conf
5.修改与入口文件index.php平级的.htaccess(如果没有新建一个)并写入以下代码:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>
官方手册:
<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>
6.重启 Apache 服务器