htaccess到nginx conf失败

时间:2019-10-26 04:10:00

标签: .htaccess nginx nginx-config

我是nginx的新手,发现.htaccess无法在其中使用。所以我尝试htaccess到nginx conf转换器。

这是htaccess代码

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^([a-zA-Z0-9\-\_]+)$ index.php?profile=$1 [NC]


# Return 404 if original request is .php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]

ErrorDocument 404 http://localhost/folder/404


Nginx conf代码

# nginx configuration

error_page 404 http://localhost/folder/404;

location / {
  if (!-e $request_filename){
    rewrite ^(.*)$ /$1.php;
  }
  rewrite ^/([a-zA-Z0-9\-\_]+)$ /index.php?profile=$1;
}

一切似乎都正常,但此行不起作用

rewrite ^/([a-zA-Z0-9\-\_]+)$ /index.php?profile=$1;

用于纯净网址,但始终显示404。任何能帮助我的Nginx专家!

0 个答案:

没有答案