简体   繁体   English

我可以将子域重定向到特定网页并使用PHP处理子域值

[英]Can I redirect a subdomain to a particular webpage and process the subdomain value with PHP

I am familiar with modifying htaccess files but not sure if the following is possible: 我熟悉修改htaccess文件,但不确定是否可以进行以下操作:

Ultimately, I want to point users to 'imaginary' subdomains (those which do not exist) so that the subdomain can be parsed correctly with PHP and MySQL to find the particular member's information. 最终,我想将用户指向“虚构”子域(不存在),以便可以使用PHP和MySQL正确解析该子域以查找特定成员的信息。

For example: 例如:

When somebody goes to www.site.com currently, it shows the parent site including information on how to become a member. 当前有人访问www.site.com时,它会显示父网站,其中包括有关如何成为会员的信息。 Once a person is a member, their 'unique' URl is: 一个人成为会员后,他们的“唯一” URl为:

www.site.com?MemberID=12345 www.site.com?MemberID=12345

ultimately, forcing the member to remember the question mark agent equals can be confusing along with the need to remember the proper capitalization and such. 最终,强迫成员记住问号代理人的平等可能会与记住正确的大小写等混淆。

I would 'like' to achieve the following: 我要实现以下目标:

www.12345.site.com www.12345.site.com

redirects to 重定向到

www.site.com/index.php (and index.php reads the 12345 like a $_GET function to properly lookup the iD, valid and retun response based on that. www.site.com/index.php(和index.php像$ _GET函数一样读取12345,以正确查找iD,有效并基于此重新调整响应。

I do realize I could achieve the same using information after the hash: 我确实意识到我可以使用哈希后的信息来实现相同的目的:

eg www.site.com/12345 例如www.site.com/12345

but the issue is we already have other pages using /xxxx to modify client content as well as I don't want to block anybody's ability to simply visit: www.site.com/contact for example 但是问题是我们已经有其他页面使用/ xxxx来修改客户端内容,并且我不想阻止任何人简单地访问以下功能:例如www.site.com/contact

(where the site redirects to index, tries to look up memberid = 'contact' and does not find any results). (网站重定向到索引,尝试查找memberid ='contact',但未找到任何结果)。

intiial thoughts: 种族思想:

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
RewriteRule (.*) http://subdomain.example.com/$1 [R=301,L]

but doesn't seem to work. 但似乎不起作用。 Note: my htaccess file also currently strips the file exnteions for all pages (ie www.site.com/contact.php displays as www.site.com/contact) 注意:我的htaccess文件目前还剥离了所有页面的文件扩展名(即www.site.com/contact.php显示为www.site.com/contact)

Any help is appreciated. 任何帮助表示赞赏。

Update regarding first suggestion - 有关第一个建议的更新-

My .htaccess is currently: 我的.htaccess当前为:

ErrorDocument 404 /404.php Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php RewriteCond %{HTTP_HOST} ^(\\w+).site.com$ [NC] RewriteRule (.*) /subdomain.php?id=%1 [L] ErrorDocument 404 /404.php选项+ FollowSymlinks RewriteCond%{REQUEST_FILENAME}上的RewriteEngine!-d RewriteCond%{REQUEST_FILENAME} .php -f RewriteRule ^(。*)$ $ 1.php RewriteCond%{HTTP_HOST} ^(\\ w +)。site .com $ [NC] RewriteRule(。*)/subdomain.php?id=%1 [L]

I would expect based off my needs that typing www.something.site.com I would be redirected to: www.site.com/processing_page.php?something 我希望根据自己的需求,输入www.something.site.com,然后将我重定向到:www.site.com/processing_page.php?something

instead, it just redirects to my mediatemple hosting page (essentially stating no subdomain named 'something' exists. 相反,它只是重定向到我的mediatemple托管页面(本质上说不存在名为“ something”的子域。

If I just go to www.site.com, it throws a 503 error: 如果我只是去www.site.com,则会引发503错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, EMAIL and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache Server at www.contendertest.com Port 80

The apache error log states: apache错误日志指出:

[Thu Jan 27 12:43:37 2011] [error] [client 1.2.3.4] Request exceeded the limit of 10 internal redirects due to probable configuration error. [2011年1月27日星期四12:43:37] [错误] [客户端1.2.3.4]由于可能的配置错误,请求超出了10个内部重定向的限制。 Use 'LimitInternalRecursion' to increase the limit if necessary. 必要时使用'LimitInternalRecursion'增加限制。 Use 'LogLevel debug' to get a backtrace. 使用“ LogLevel调试”获取回溯。

Attempt 2 尝试2

My .htaccess file is now stripped to: 我的.htaccess文件现在被剥离为:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.+)\.site\.com
RewriteRule .* http://site.com/processing_page.php?ID=%1 [L,R]

This still directs to my media temple random landing page however. 但是,这仍然指向我的媒体寺庙随机登录页面。

Your are looking for " RewriteCond backrefereces ". 您正在寻找“ RewriteCond backrefereces ”。 They take the form %1 rather than the usual $1 for the current RewriteRule. 它们采用%1的形式,而不是当前RewriteRule的通常$1的形式。

So your example might look like: 因此,您的示例可能如下所示:

RewriteCond %{HTTP_HOST} ^(\w+).example.com$ [NC]
RewriteRule (.*) /subdomain.php?id=%1 [L]

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

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