Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache cms后端的Nginx重写规则_Apache_.htaccess_Mod Rewrite_Nginx - Fatal编程技术网

Apache cms后端的Nginx重写规则

Apache cms后端的Nginx重写规则,apache,.htaccess,mod-rewrite,nginx,Apache,.htaccess,Mod Rewrite,Nginx,我需要使nginx服务器中的url重写规则(服务器块)与我以前的apache服务器中的规则相同。 这是.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] 此代码位于

我需要使nginx服务器中的url重写规则(服务器块)与我以前的apache服务器中的规则相同。
这是.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]
此代码位于我的网站中,因为我需要在登录后隐藏在地址栏文件夹(/admin/)中,其中包含文件。当有人已经登录时,地址栏就像www.domain.com/username,当你点击菜单时,地址就像www.domain.com/username/page1www.domain.com/username/page2www.domain.com/username/page3。 这就是我在nginx中需要实现的目标。因为现在是完全没有功能的后端。当我登录到后端时,我被重定向到www.domain.com/username,但在屏幕上我只能看到未找到的文件。只有在我手动添加www.domain.com/admin/index.php时,后端才会工作

这是我对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

我将非常感激任何帮助!
非常感谢。

您将此信息放在了您的/位置,这意味着在您将此信息放在此处之前,您的所有请求都不匹配。在创建位置之前,必须为此条目创建特定的位置角色/

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;
} 

如何区分后端和前端url的区别?还是仅仅是后端?@Mohammad AbuShady frontend类似于www.example.com/frontend-pages,在登录后端www.example.com/username和后端www.example.com/username/pages中的页面之后-backend@MohammadAbuShady问题是悬赏有
用户名
有任何随机用户名吗?比如
example.com/makromat
?@MohammadAbuShady是的。谢谢