![]() |
|
|||||||
| 建站交流 讨论网站建设的基本方法、技巧、空间问题讨论、域名交流、 资源分享、技术交流,站长们经常进来看看噢! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
#1
IP: 222.184.115.77
|
|||
|
|||
|
I have a main website of example.com, and I want to add a second (and more) domain named example2.com, with a home directory of example.com/example2/
example2.com is a "parked" domain name, ie it is initially directed to the public root directory of example.com, the main account. I am told I need.htaccess coding that will 1. set the public root directory of example2.com to example.com/example2/ 2. retain the visible url of example2.com *after* internal redirection to example2's public root directory So the user types example2.com, is taken to the public root directory of example2.com (through.htaccess programming), sees example2.com in the URL field of the browser, but in fact has been taken "underneath" to example.com/example2. Can anyone show me how this is done, or point me to some documentation? Thanks! |
|
#2
IP: 222.184.115.77
|
|||
|
|||
|
You will probably want to use the RewriteCond directive examining the server variable %{HTTP_HOST} to match the names of your various domains, and then if the name matches, do an internal rewrite --not a redirect-- to the subdirectory where that domain's files are located.
If your code is in .htaccess, you will also need to test the requested URL to make sure that you have not previously rewritten the request to the subdirectory. Without this test, your .htaccess rules will loop recursively, until the server or client reaches its maximum redirection limit. As a simple example, consider: RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com RewriteCond $1 !domain1/ RewriteRule (.*) /domain1/$1 [L] RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com RewriteCond $1 !domain2/ RewriteRule (.*) /domain2/$1 [L] This approach is workable for just a few domains, but gets unwieldy for more than a half-dozen or so. For more than just a few domain-subdirectories, it is best to 'tag' the subdirectories with a common prefix to simplify the anti-looping prevention, and to use back-references to carry the name of the domain into the last part of subdirectory name. Something like: RewriteCond %{HTTP_HOST} ^(www\.)?(domain1omain2omain3)\.com [OR] RewriteCond %{HTTP_HOST} ^(www\.)?(domain4omain5)\.net RewriteCond $1 !dsd_ RewriteRule (.*) /dsd_%2/$1 [L] Here, the we use "dsd_" as a 'tag' to identify all domain-related subdirectories, so that the rewrite looping that I described can be prevented; In this example, a request for the page "foo.html" in the domain "widgets.com" (with or without the leading "www.") will be internally rewritten to "/dsd_widgets/foo.html". Local variable $1 back-references the requested local URL-path (the "filename"), while local variable %2 back-references the requested hostname. Variable %1, referencing the optional "www.", is not used in this example. Obviously, there are many possible variations on what you might want to do, so these are just two examples to get you started. Important: Replace all broken pipe "?quot; characters above with solid pipe characters from your keyboard before trying to use this code; Posting on this forum modifies the pipe characters. For more information, see the documents cited in our forum charter and the tutorials in the Apache forum section of the WebmasterWorld library. Once you get your code working, then we can discuss how to prevent "/dsd_widgets/foo.html" from showing up in the search engines... :) |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Where can I change the configuration? | smiling | 服务器环境搭建 | 0 | 2006-05-26 10:55 PM |