网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > 建站交流
User Name
Password
 
FAQ Members List Calendar Cheap Glasses Mark Forums Read

建站交流 讨论网站建设的基本方法、技巧、空间问题讨论、域名交流、
资源分享、技术交流,站长们经常进来看看噢!

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2   IP: 222.184.115.77
Old 2007-08-18, 01:39 AM
smiling smiling is offline
高级会员
 
Join Date: 2006-02-12
Posts: 502
smiling 正向着好的方向发展
Default

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\.)?(domain1omain2omain3)\.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?(domain4omain5)\.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... :)
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where can I change the configuration? smiling 服务器环境搭建 0 2006-05-26 10:55 PM

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:28 PM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.