在Nginx中将常规URL重写为SEF URL

时间:2018-08-02 11:22:36

标签: url nginx url-rewriting

我正在尝试完成某些URL重写,同时能够使用try_files重定向配置文件页面。这是我的示例Nginx配置文件。

server {
    listen 80;
    server_name         example.com www.example.com;
    location / {
        root            /path/to/example.com;
        index           index.php index.htm index.html;
[A]     rewrite         ^([^.]*[^/])$ $1/ permanent;
    }
    location ~ ^/(?<user>[A-Za-z0-9\.\_]+)/$ {
[B]     try_files       $uri $uri/ /$uri/ /profile/user/$user/?rewrite=1&$args;
    }
    location ~ \.php$ {
        root            /path/to/example.com;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include         fastcgi_params;
        fastcgi_intercept_errors off;
    }
    location ~ /\.ht {
        deny            all;
    }
}

我已经能够在[A]和[B]的帮助下映射以下内容:

http://www.example.com/cena/
pointing to
http://www.example.com/profile/user/cena/

与此同时,我想做到这一点:

http://www.example.com/option/users/view/login
to rewrite to
http://www.example.com/?option=ext_users&view=login

http://www.example.com/option/users/action/login
to rewrite to
http://www.example.com/?option=ext_users&action=login

0 个答案:

没有答案