简体   繁体   English

.htaccess 使用 session 变量重写作为 RewriteBase

[英].htaccess rewrite using session variables as RewriteBase

I'm currently using sub-domains to segment clients to their own websites - this is only for appearance to show the client name in the URL. However, there is no need to use Subdomains.我目前正在使用子域将客户细分到他们自己的网站 - 这只是为了在 URL 中显示客户名称。但是,没有必要使用子域。 Instead, I'd like to have 1 website and rewrite the url so they each client's name appears like this in the URL like this: https://test.com/CLIENT_NAME/index.php相反,我想拥有 1 个网站并重写 url,以便他们每个客户的名称在 URL 中显示如下: https://test.com/CLIENT_NAME/index.php

When the client first visits https://test.com/CLIENT_NAME/ if the session variable "CLIENT_NAME",isset.当客户端第一次访问https://test.com/CLIENT_NAME/时如果session变量“CLIENT_NAME”,isset。 I'd like to route them to test.com/index?php?id=CLIENT_NAME (but keep the URL showing as https://test.com/CLIENT_NAME/ ) so I can use the $_GET variable from "id" to get their data from the database and set the session variables.我想将它们路由到 test.com/index?php?id=CLIENT_NAME(但保持 URL 显示为https://test.com/CLIENT_NAME/ )所以我可以使用 $_GET 变量从“id”到从数据库中获取数据并设置 session 变量。

Once logged in and the session variable of CLIENT_NAME is set, I'd just like to rewrite each URL to have /CLIENT_NAME/ after the base domain, but effectly the site will all pages as though it's just the base domain (without /CLIENT_NAME/).一旦登录并设置了 CLIENT_NAME 的 session 变量,我只想重写每个 URL 以在基域之后有 /CLIENT_NAME/,但实际上该站点将所有页面都当作它只是基域(没有 /CLIENT_NAME/ ).

For example once logged in: the URL will appear as test.com/CLIENT_NAME/page_1 but the server will access the file stored in the root public_html folder that would usually be accessed by visiting test.com/page_1.php.例如,一旦登录:URL 将显示为 test.com/CLIENT_NAME/page_1,但服务器将访问存储在根 public_html 文件夹中的文件,该文件夹通常通过访问 test.com/page_1.php 来访问。

At the same time, it would be great to remove ".php" from the end of each webpage (like in the above example).同时,最好从每个网页的末尾删除“.php”(如上例)。

Thanks for your assistance!感谢你的协助!

I've tried all sorts of other examples found on here, but it seems everyone uses a fixed parameter for the RewriteBase, instead of checking the session variables to see if something is set there and then using that value as the RewriteBase if it is, or redirecting the user to a GET request (with the url masked) to set the session variables.我已经尝试了在这里找到的各种其他示例,但似乎每个人都为 RewriteBase 使用固定参数,而不是检查 session 变量以查看是否设置了某些内容,然后将该值用作 RewriteBase,如果是的话,或将用户重定向到 GET 请求(屏蔽 url)以设置 session 变量。

You won't believe this, but I managed to find the answer with the help of ChatGPT lol你不会相信这一点,但我在 ChatGPT 的帮助下设法找到了答案 哈哈

It gave me this:它给了我这个:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/portals/
RewriteRule ^([^/]+)/(.*)$ /index.php?folder=$1&path=$2 [L,QSA]

which I changed to this:我改成了这个:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/portals/
RewriteCond %{REQUEST_URI} !^/portals/index.php
RewriteCond %{REQUEST_URI} !^/includes/
RewriteCond %{REQUEST_URI} !^/home/
RewriteRule ^([^/]+)/(.*)$ portals/$2?portalID=$1&path=$2 [L,QSA]

Thanks for your help everyone!谢谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM