【问题标题】:how to enable url rewriting in nginx on windows pc如何在windows pc上的nginx中启用url重写
【发布时间】:2015-01-30 18:32:44
【问题描述】:

我在 Windows 8.1 pro 上使用 winginx。我是新手。我想在 Windows 上为 nginx 启用 url 重写,这样这样的链接“http://mysite.dev/portfolio/latest/business-card-design/”就可以正常工作。我想专门使用 wordpress 和 laravel。我找到了如何将 .htaccess 文件转换为 nginx,但我不知道将它们放在哪里。希望各位高手能理解我的问题。对不起我的英语不好。请帮我。谢谢。

【问题讨论】:

  • 看看这里:nginx http rewrite module,它可以帮助你做你想做的事。
  • 您好,非常感谢您的回复。但很抱歉,我无法使用链接解决我的问题。我对 nginx 真的很陌生。我不知道如何为 wordpress 漂亮的 url 配置 url 重写。它是比 xmapp 更快的服务器。但我很遗憾我无法使用漂亮的 url 使其适用于我的 wordpress 主题开发。我在 youtube 上的谷歌上搜索解决方案,但找不到合适的解决方案。请帮助我提供易于理解的细节。非常感谢。
  • 不要急于求成,花点时间找到你要找的东西,做你想做的事。我不确切知道如何使用 nginx 处理 wordpress,但我知道谷歌知道它;)所以看看 herehere
  • 您好,我并不着急,我花了 7 天多的时间研究在 windows 上的 nginx 上为 wordpress 启用漂亮 url 的解决方案,但我无法获得结果。因为你给我的所有信息对于像我这样的新手来说都过于复杂了。他们没有明确说明要编辑哪个文件以及在哪里放置一些代码以启用漂亮的 url。有没有办法像一个简单的进程 .htaccess 文件一样启用 url 重写?请考虑我不是专家。我对 nginx 完全陌生。我真的需要一些简单的解决方案。请帮我一个直接的解决方案。谢谢
  • 好的,我给你一个答案,看看,告诉我它是否适合你。

标签: .htaccess mod-rewrite nginx


【解决方案1】:

我下载了Winginx 并安装了Wordpress 4.0.1,这是我的配置:

server {

    listen 127.0.0.1:80;
    server_name example.com www.example.com;

    root home/example.com/public_html;

    index index.php index.html;

    log_not_found off;
    access_log logs/example.com-access.log;

    charset utf-8;

    location ~ /\. { deny all; }
    location = /favicon.ico { }
    location = /robots.txt { }      

    if (!-e $request_filename) {
        rewrite ^(.+)$ /index.php?q=$1 last;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;
    }

}

有了这个由 Winginx 生成的配置,我的网站工作正常,我唯一添加的部分是 URL 重写部分:

if (!-e $request_filename) {
    rewrite ^(.+)$ /index.php?q=$1 last;
}

当然,您必须从“设置”>“固定链接”中选择您的固定链接设置,以获得您想要的 URL。

【讨论】:

  • 非常感谢亲爱的。有用。我必须根据我的服务器名称及其根来更改服务器名称和根值。哇哦。效果很好。我非常高兴。再次感谢您的大力帮助。
猜你喜欢
  • 2019-01-24
  • 2011-05-18
  • 1970-01-01
  • 2015-12-20
  • 1970-01-01
  • 2022-01-25
  • 2018-04-06
  • 1970-01-01
  • 2016-02-07
相关资源
最近更新 更多