繁体   English   中英

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

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

我熟悉修改htaccess文件,但不确定是否可以进行以下操作:

最终,我想将用户指向“虚构”子域(不存在),以便可以使用PHP和MySQL正确解析该子域以查找特定成员的信息。

例如:

当前有人访问www.site.com时,它会显示父网站,其中包括有关如何成为会员的信息。 一个人成为会员后,他们的“唯一” URl为:

www.site.com?MemberID=12345

最终,强迫成员记住问号代理人的平等可能会与记住正确的大小写等混淆。

我要实现以下目标:

www.12345.site.com

重定向到

www.site.com/index.php(和index.php像$ _GET函数一样读取12345,以正确查找iD,有效并基于此重新调整响应。

我确实意识到我可以使用哈希后的信息来实现相同的目的:

例如www.site.com/12345

但是问题是我们已经有其他页面使用/ xxxx来修改客户端内容,并且我不想阻止任何人简单地访问以下功能:例如www.site.com/contact

(网站重定向到索引,尝试查找memberid ='contact',但未找到任何结果)。

种族思想:

Options +FollowSymlinks
RewriteEngine On

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

但似乎不起作用。 注意:我的htaccess文件目前还剥离了所有页面的文件扩展名(即www.site.com/contact.php显示为www.site.com/contact)

任何帮助表示赞赏。

有关第一个建议的更新-

我的.htaccess当前为:

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]

我希望根据自己的需求,输入www.something.site.com,然后将我重定向到:www.site.com/processing_page.php?something

相反,它只是重定向到我的mediatemple托管页面(本质上说不存在名为“ something”的子域。

如果我只是去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

apache错误日志指出:

[2011年1月27日星期四12:43:37] [错误] [客户端1.2.3.4]由于可能的配置错误,请求超出了10个内部重定向的限制。 必要时使用'LimitInternalRecursion'增加限制。 使用“ LogLevel调试”获取回溯。

尝试2

我的.htaccess文件现在被剥离为:

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

但是,这仍然指向我的媒体寺庙随机登录页面。

您正在寻找“ RewriteCond backrefereces ”。 它们采用%1的形式,而不是当前RewriteRule的通常$1的形式。

因此,您的示例可能如下所示:

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