本文介绍了mod_rewrite:删除子域并转换为URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,在这里我为每个客户端保留一个子域,例如: 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.

我该如何实现?

推荐答案

我认为您正在尝试执行类似的操作?

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参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 16:39