问题描述
我有一个网络应用程序,我为每个客户端保留一个子域,例如:http://clientNo32.myApp.com由于一些服务器令人眼花缭乱,我必须将这些东西转发到我的新服务器 http://123.456.78:1002/clientNo32/app/index.php
I have a web app, where I keep a subdomain for every client eg: http://clientNo32.myApp.comDue to some server hazzling I have to forward this stuff to my new server at http://123.456.78:1002/clientNo32/app/index.php
文件夹clientNo32"不存在,它只是我想从 URL 获取的参数.
The folder "clientNo32" does NOT exist, it's only a parameter I want to get from the URL.
我怎样才能做到这一点?
How can I achieve this?
推荐答案
我认为您正在尝试做这样的事情?
I think you're trying to do something like this?
RewriteEngine On
# Don't know if you need this, exclude www hosts
RewriteCond %{HTTP_HOST} !^www [NC]
# Make sure we don't already have a "cId" in the query string
RewriteCond %{QUERY_STRING} !cId=
# match the subdomain
RewriteCond %{HTTP_HOST} ^([^.]+).myapp.com$ [NC]
# add subdomain to URI as a query string
RewriteRule ^(.*)$ /app/index.php?cId=%1 [L,QSA]
这使得当您请求以 http://clientNo32.myApp.com/ 开头的任何内容时,它被重写为 /app/index.php?cId=clientNo32
This makes it so when you request anything starting with http://clientNo32.myApp.com/, it gets rewritten to /app/index.php?cId=clientNo32
这篇关于mod_rewrite:剥离子域并转换为 URL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!