Nginx rewrite 设置
server{
... 省略
location / {
index index.php index.html index.htm;
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则 if (!-e $request_filename)
{
#地址作为将参数rewrite到index.php上。
rewrite ^/(.*)$ /index.php?s=$1;
#若是子目录则使用下面这句,将subdir改成目录名称即可。
#rewrite ^/subdir/(.*)$ /subdir/index.php?s=$1;
}
}
... 省略}
Apache rewrite 设置
1. httpd.conf配置文件中加载了mod_rewrite.so模块
# LoadModule rewrite_module path/mod_rewrite.so
取消注释
LoadModule rewrite_module path/mod_rewrite.so
2. AllowOverride None 将None改为 All
<Directory /> ... AllowOverride All ... </Directory>
3. 重启 apache
Apache下如果.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>