让phpStudy2018 Nginx 支持WordPress自定义链接

2019年11月4日19:21:56 发表评论 1,374 views

只适合Windows本地环境(服务器上没试过),默认phpStudy2018 Nginx并不支持WordPress自定义链接,可以通过修改配置文件支持让其支持。

让phpStudy2018 Nginx 支持WordPress自定义链接

用文本编辑工具打开PHPTutorial\nginx\conf目录的nginx.conf文件,修改前做个备份,以免修改失误,造成phpStudy无法启动。

搜索autoindex,找到类似:

  1. server {
  2. listen 80;
  3. server_name localhost;
  4.  
  5. #charset koi8-r;
  6.  
  7. #access_log logs/host.access.log main;
  8. root "I:/phpStudy/PHPTutorial/WWW";
  9. location / {
  10. index index.html index.htm index.php l.php;
  11. autoindex on;
  12. }

在其下面添加设置代码,有两种情况:

一、WordPress程序直接安装在PHPTutorial\WWW目录中:

  1. if (-f $request_filename/index.html){
  2. rewrite (.*) $1/index.html break;
  3. }
  4. if (-f $request_filename/index.php){
  5. rewrite (.*) $1/index.php;
  6. }
  7. if (!-f $request_filename){
  8. rewrite (.*) /index.php;
  9. }

二、WordPress程序安装在PHPTutorial\WWW子目录中,比如:wordpress:

  1. if (-f $request_filename/wordpress/index.html){
  2. rewrite (.*) $1/wordpress/index.html break;
  3. }
  4. if (-f $request_filename/wordpress/index.php){
  5. rewrite (.*) $1/wordpress/index.php;
  6. }
  7. if (!-f $request_filename){
  8. rewrite (.*) /wordpress/index.php;
  9. }

修改其中的wordpress为你子目录名称。

最后重启phpStudy,试试设置自定义链接是否可以正常打开了。

phpStudy 最新版本是8.0,此方法并未在此版本中试过。

可以到官网下载适合的版本:https://www.xp.cn/download.html

站长小智

发表评论

您必须登录才能发表评论!