以前一直是用Nginx整TP框架,但考虑到Win本地开发用Apache性能会好一些,就尝试换了过来,但无奈发现官方提供的伪静态就是个坑,死活不生效,经过搜索发现,我这边的问题是因为官方提供的伪静态只在部分Apache上没有问题,别的都是不行的。

 

有两种可能性,解决方法都很简单,如下:

 

一.替换规则

1
2
3
4
5
6
7
8
<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>

替换成:

1
2
3
4
5
6
7
8
<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

实际上就是将最后一行规则改掉就行

 

二.伪静态功能未启用

httpd.conf配置文件中加载了mod_rewrite.so模块

AllowOverride None 将None改为 All

重启Apache