注意:伪静态文件必须放在网站根目录才会生效
Apache:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|images|robots\.txt)
# RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^(.*)$ index.php
Nginx:
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
或者:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
或者:【二级目录下面伪静态配置规则】
location /test/www/ {
try_files $uri $uri/ =404;
if (!-e $request_filename) {
rewrite ^\/test\/www\/(.*)$ /test/www/index.php?s=$1 last;
}
}