开发者

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

开发者 https://www.devze.com 2023-02-07 04:21 出处:网络
I am familiar with modifying htaccess files but not sure if the following is possible: Ultimately, I want to point users to \'imaginary\' subdomains (those which do not exist) so that the subdomain c

I am familiar with modifying htaccess files but not sure if the following is possible:

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.

For example:

When somebody goes to www.site.com currently, it shows the parent site including information on how to become a member. Once a person is a member, their 'unique' URl is:

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

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.

I do realize I could achieve the same using information after the hash:

e.g. 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

(where the site redirects to 开发者_C百科index, tries to look up memberid = 'contact' and does not find any results).

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 (i.e. www.site.com/contact.php displays as www.site.com/contact)

Any help is appreciated.

Update regarding first suggestion -

My .htaccess is currently:

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]

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

instead, it just redirects to my mediatemple hosting page (essentially stating no subdomain named 'something' exists.

If I just go to www.site.com, it throws a 503 error:

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:

[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. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Attempt 2

My .htaccess file is now stripped to:

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". They take the form %1 rather than the usual $1 for the current RewriteRule.

So your example might look like:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号