【问题标题】:apache .htaccess to nginx rewriteapache .htaccess 到 nginx 重写
【发布时间】:2016-08-11 01:11:55
【问题描述】:

.htaccess 文件,代码如下

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tag/([A-Za-z0-9_]+)$ hashtag.php?hashtag=$1
RewriteRule ^([A-Za-z0-9_]+)$ profile.php?username=$1

在 nginx 重写中,我是这样设置的

location / {
    if (!-e $request_filename){
            rewrite ^/([A-Za-z0-9_]+)$ /profile.php?username=$1;
            }
    if (!-e $request_filename){
            rewrite ^tag/([A-Za-z0-9_]+)$ /hashtag.php?hashtag=$1;
    }

}

可以访问domain.com/hashtag.php?hashtag=123,domain.com/profile.php?username=name,也可以访问domain.com/name,但是不能访问domain.com /tag/123,它显示 404 错误。你能帮助我吗?非常感谢。

【问题讨论】:

  • 也许你可以改变重写的顺序,把标签放在第一位:)?
  • @DusanBajic 也是同样的结果,404 错误。

标签: php apache .htaccess mod-rewrite nginx


【解决方案1】:

我的nginx rewrite configure有错误,应该是

rewrite ^/tag/([A-Za-z0-9_]+)$ /hashtag.php?hashtag=$1;

我想念 /,关闭这个问题。

【讨论】:

    猜你喜欢
    • 2014-04-24
    • 2016-01-16
    • 2014-08-09
    • 2011-08-21
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    • 2020-01-10
    相关资源
    最近更新 更多