重写code从htaccess的到nginx的配置?

编程入门 行业动态 更新时间:2024-10-08 10:57:02
本文介绍了重写code从htaccess的到nginx的配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有问题,实现从htaccess文件我重写code到nginx的配置。 我已经尝试过发生器: winginx/htaccess 以生成我重写 code。

I have problem with implement my rewrite code from htaccess file into nginx config. I've already tried generator : winginx/htaccess for generate my rewrite code.

我的nginx的设置code:

server { listen 80; server_name example; return 301 $scheme://www.example$request_uri; } server { listen 80; root /usr/share/nginx/www; index index.php; server_name www.example; error_page 404 www.example/404.php; autoindex off; error_log /usr/share/nginx/www/nginx_error.log warn; location / { rewrite ^([^\.]*)$ /$1.php; } location = / { rewrite ^ /index.php; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; } }

我想从我的.htaccess实现这样的:

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ admin/index.php?hotelname=$1&do=$2 [QSA] RewriteRule ^(([A-Za-z0-9-/]+)+)$ admin/index.php?hotelname=$1 [L]

生成$ C $从工具C:

location / { rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ /admin/index.php?hotelname=$1&do=$2; rewrite ^/(([A-Za-z0-9-/]+)+)$ /admin/index.php?hotelname=$1 break; }

我已经alredy尝试实施code这最后几行到我的位置,块,但不工作.. 我会很greateful每一个意见! 此致 Makromat

I have alredy tried implement this last lines of code to my location blocks but not working at all.. I will be very greateful for every opinion! Regards Makromat

推荐答案

通常重写在使用nginx的思维方式nginx的更好管理。而这种思维的新方法更是以 try_file 。

Usually rewrites are better managed in nginx using nginx way of thinking. And this new way of thinking is more based on try_file.

所以,你可以尝试类似的东西(未经测试):

So you may try something like that (untested):

location ^~ "/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)" { try_files $uri admin/index.php?hotelname=$1&do=$2&$args; } location ^~ "(([A-Za-z0-9-/]+)+)" { try_files $uri /admin/index.php?hotelname=$1; } location = / { rewrite ^ /index.php; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; }

如果在给定的直接访问 $ URI 不应该发生的,然后删除该部分从try_files。现在我还不能确定你的第二个正则表达式的(([A-ZA-Z0-9 - /] +)+),为什么不使用:

If direct access on given $urishould never happen, then remove that part from the try_files. Now I'm also unsure of your second regex (([A-Za-z0-9-/]+)+), why not using:

location ^~ "/([A-Za-z0-9-/])+"

location ^~ "/([A-Za-z0-9-])+/"

因此​​,有可能一些我没有看到,甚至在你的Apache重写。

So there's maybe something I do not see, even in your apache rewrites.

更多推荐

重写code从htaccess的到nginx的配置?

本文发布于:2023-11-02 06:14:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   code   nginx   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!