php - htaccess redirect subdomains to certain page? -


I need all subdomains to redirect to a specific page without actually changing the URL, because I Depending on the specific page which is the subdomain in the URL, display different content.

Assuming my site is located at testdomain.com/site1 /

, I want all subdomains, such as xyz.testdomain.com/site1 / or here As long as xyz.testdomain.com has to be redirected to a specific page on

, then the browser needs to be loaded, but the URL will still be xyz.testdomain.com.

Its purpose is that a person can go to abc.testdomain.com or xyz.testdomain.com and will take both users to testdomain.com/site1/index.php/test.php, And then at test.php, I have some code that will catch the URL, and if the URL is abc.testdomain.com, it will display certain content, though the subdomain xyz.testdomain.com will display different content.

Is there anything I can do in Http? If so, then how? You can hack it together by using

mod_rewrite .

  # Step 1: If the user goes to example.com or www.example.com # then we do not want to redirect them. (S = 1 says leave the next rule) Rewinded% {HTTP_HOST} ^ (www)? Example \ .com RivetArules ^ - [S = 1] # Step 2: Something else is redirected to our capture script # Option1: They keep the path they went on, but the domain # i.e. Xyz.example.com/abc/def.txt = & gt; /var/www/cgi-bin/abc/def.txtRewriteRule ^ /? (. *) / Var / www / cgi-bin / $ 1 [QSA, L] # or option 2: Take all requests in the same file # ie xyz.example.com/abc/def.txt = & gt; ; /var/www/cgi-bin/myfile.php Rewrite rules ^ /var/www/cgi-bin/myfile.php [QSA, L]   

QSA It asks for the forwarding of the query string, L asks to stop looking for more redirection (not absolutely necessary, but sometimes it helps if you have a lot of Something is there).

You can send the variable in your script as a parameter to the query, and the QSA flag ensures that they do not replace the original values;

  # xyz.example com / abc / def.txt = & gt; /var/www/cgi-bin/myfile.php?host=xyz.example.com&path=/abc/def.txt RewriteRule ^ /? (. *) /var/www/cgi-bin/myfile.php? Host =% {HTTP_HOST} and Path = / $ 1 [QSA, L]   

This means that you are not concerned about finding out where the request from within your script came from Really can be impossible, I'm not sure). Instead you can read it as a normal parameter (make sure to ensure it is also a hack like a normal parameter).

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -