Using htaccess to bind multiple domain names to a virtual host to correspond to different subdirectories

Source: Internet
Author: User

My blog and geoserver Chinese community has been in the same virtual host, has been done a jump, www. your domain name. com access to the words jump to http://www. Your domain name, com/wordpress, opengeo.cn domain name to access the word jump to Http://opengeo.cn/dz

Yesterday found a solution to solve, do not jump, www. your domain name. com directly access to the content of WordPress below, opengeo.cn direct access to the content of DZ below, do not have the tape directory.

Apache+php hosts usually solve two solutions to this problem, one is the use of Apache VirtualHost, one is the use of Apache htaccess. Million network of virtual host does not support the former one, had to use htaccess.

I'll just post the code directly below.

  code is as follows copy code
# opens Rewriteengine mode
Rewriteengine on
.
Rewritecond%{http_host} ^ (www.)? opengeo.cn$
Rewritecond%{request_uri}!^/dz/
Rewritecond%{request_filename}!-f
Rewritecond%{REQUEST_FI Lename}!-d
Rewriterule ^ (. *) $/dz/$1
Rewritecond%{http_host} ^ (www.)? opengeo.cn$
Rewriterule ^ (/) $ dz/index.php [L]
 
Rewritecond%{http_host} ^ (www.)? Your domain name. (COM|CN) $
Rewritecond%{request_uri}!^/wordpress/
Rewritecond%{request_filename}!-f
RewriteCond%{REQUE St_filename}!-d
Rewriterule ^ (. *) $/wordpress/$1
Rewritecond%{http_host} ^ (www.)? Your domain name. (COM|CN) $
Rewriterule ^ (/) $ wordpress/index.php [L]

Make a simple explanation for the instructions above:

The Rewritecond directive defines the conditions under which a rule takes effect, and it can have one or more rewritecond instructions before a rewriterule instruction indicates the conditions that must be met to perform the rewriterule.
Rewriterule doesn't explain, it's a specific rule.

. htaccess file Contents
Rewriteengine on
# change your domain name. xxx to the domain name you want to bind to.
Rewritecond%{http_host} ^ (www.)? Your domain name. xxx$

# Change the subfolder to the directory you want to bind to.
Rewritecond%{request_uri}!^/subfolder/

# don't change the following two lines.
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d

# change Dev to the directory to bind to.
Rewriterule ^ (. *) $/dev/$1

# change your domain name. xxx to the domain name you want to bind to
# change Dev to the directory to bind to.
# dev/behind is the first document index.php, index.html
Rewritecond%{http_host} ^ (www.)? Your domain name. xxx$
Rewriterule ^ (/) $ wordpress/index.php [L]

Note that Windows cannot create htaccess files directly because Windows does not support files without a primary filename, and we can create. htaccess files as follows

Method 1. Start-run-type cmd, open cmd window

At this point the cmd window path is c:/documents and settings/username>

Type the following (excluding information in parentheses):

Copy con. htaccess (carriage return)

(Press Ctrl+z carriage return)

The screen prompts are as follows:

C:/Documents and Settings/admin>copy con htaccess.
^z
1 files have been copied.

At this point, back to the desktop, double-click My Computer to enter c:/documents and Settings/username

You can see the file you want ". htaccess"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.