Apache Rewrite experience
Recently, the company wants to transfer servers. Dozens of websites are running on the servers. During the transfer, services are not affected. Therefore, Apache mod_rewrite is used for some processing.
The general environment is like this. The server has the site [1-50] .TA.com domain name and site [1-50] .TB.com domain name. Before you start to transfer the server, first, point site [1-50] .TB.com to the new server IP address. At the same time, run Apache on the new IP address and write the access Rewrite of siteX.TB.com back to TA.com. After one day, resolve TB.com to the new IP address, transfer the database and WEB service to the new IP address, and write the Apache Rewrite on the original server to SiteX.TB.com. Some users cache the DNS, as a result, the original server is still accessed.
The Rewrite statement is roughly as follows:
Copy codeThe Code is as follows: # Load mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so
# Enable mod_rewrite
RewriteEngine On
# Enable Log (for debugging)
RewriteLog "logs/rewrite. log"
RewriteLogLevel 9
# Only Rewrite the domain names starting with siteX, demo, and support
RewriteCond % {SERVER_NAME} ^ (site | demo | support) [NC]
# Add the host name before the URI
RewriteRule ^ (. +) % {SERVER_NAME} $1 [C]
# Convert all xxx.ta.com/#on this server to xxx.tb.com /*
RewriteRule ^ [a-z0-9] + )\. ([0-9a-z \.] + )/(. *) http: // $1 \. TB \. com/$3 [NC, R, L]
If Apache is configured with a virtual host, this configuration should be written to the default virtual host configuration.