转换为Nginx规则

时间:2019-04-30 06:52:47

标签: .htaccess nginx url-rewriting

早上好,有人可以帮助我将.htaccess转换为nginx吗?

.httacess

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ ./$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ ./$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

我尝试了很多事情,但是我只是无法获得正确的公式来使其起作用。现在是我的配置:

location /dev/links {
  if (!-e $request_filename){
    rewrite ^/([^/]+)/$ /$1 redirect;
  }
  rewrite ^/(.+)\.php$ /$1 redirect;
  rewrite ^/([^/.]+)$ /$1.php last;
}

如果不是/ dev / links子目录,则不是根目录

0 个答案:

没有答案