Nginx 解決方案:
網上盛傳的方法是:
在 /etc/nginx/nginx.conf文件的 loction / {} 中添加
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; }
特別注意:這種設置方法小編測試是無效的,會導致網站排版亂碼。
正確的設置方式是loction / {}中添加配置:
#加入如下一條命令即可
try_files $uri $uri/ /index.php?$args;
修改完成后重啟Nginx服務器生效。
service nginx restart
Apache解決方案:
/etc/httpd/conf/httpd.config 文件
原因一:Apache中的rewrite模塊沒有開啟,去除這一行前面的#號就可以了
LoadModule rewrite_module modules/mod_rewrite.so
原因二:AllowOverride Not Enabled;服務器可能沒打開AllowOverride。如果httpd.config的AllowOverride設置的是None,那.htaccess將被忽略。找到以下2處位置並修改:
<Directory /> Options FollowSymLinks AllowOverride All </Directory>
<Directory /var/www/html> # … other directives… AllowOverride All </Directory>
修改完成后,要重啟Apache才能生效。
service httpd restart