我有问题,实现从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的配置?
发布评论