对于CMS后台Nginx的重写规则 [英] Nginx rewrite rule for cms backend

查看:167
本文介绍了对于CMS后台Nginx的重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在nginx的服务器的URL重写规则(服务器模块)同样喜欢在我的previous Apache服务器。
这是的.htaccess code什么,我需要实现(转换)到我现有的:

I need to make url rewrite rules (server blocks) in nginx server same like in my previous apache server.
This is code from .htaccess what I need to implement (convert) into my existing one:

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]

这code是在我的网站,因为我需要在地址栏中的文件夹为隐藏(/管理/),其中在登录后位置的文件。而当有人已经登录,地址栏中就像 www.domain.com/username ,当你点击菜单联系地址是一样的 www.domain.com/username/page1 www.domain.com/username/page2 www.domain.com/username/page3 。 这就是我需要的nginx才达到。因为现在是没有功能齐全的后端。当我登录到后台,我重定向到 www.domain.com/username ,但是在屏幕上,我可以看到的只是文件未找到。在后台只有当我manualy工作添加 www.domain.com/admin/index.php

This code is in my website because I need to hide in adress bar folder(/admin/) where is located files after login. And when somebody is already login, adress bar is like www.domain.com/username and when you click to menu adress is like www.domain.com/username/page1, www.domain.com/username/page2, www.domain.com/username/page3. This is what I need to achive in nginx. Because now is complete backend without function. When I login to backend, I'm redirected to www.domain.com/username but on screen I can see only File not found. In backend working only when I manualy add www.domain.com/admin/index.php.

这是我的实际配置为nginx的:

This is my actual config for nginx :

server_names_hash_bucket_size  64;

server {
    listen 80;
    server_name example.com;
    return 301 $scheme://www.example.com$request_uri;
}

server {
        listen 80;
        root /usr/share/nginx/www;
        index index.php;
        server_name www.example.com;
        error_page 404 http://www.example.com/404.php;
        autoindex off;



   location / {
        rewrite ^([^\.]*)$ /$1.php;
    }

    location = / {
        rewrite ^ /index.php;
    }


    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
      }
}

当我试图改变我的块:

location / {
        rewrite ^([^\.]*)$ /$1.php;
        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;
    }

每个我的CSS文件中有错误500 ...

Each my css file have error 500...

我会很感激的任何帮助! 非常感谢。

I will be very grateful with any help! Thanks a lot.

推荐答案

您在你/的位置,这意味着所有的请求不匹配你把这儿之前把这个。你必须创建特定的这个记录的位置之前/

You are putting this in your / location, that means that all your requests not matched before you drop here. You have to create a location role specific for this entry before the location /

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

这篇关于对于CMS后台Nginx的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆