Apache 只重写域名而不是主机名
Apache rewrite only domain name not the hostname
我有以下内容:
http://test.inside/index.html?something=big
http://otherthing.inside/index.html?something=else
"test" 和 "otherthing" 可以是任何东西。我想捕获在 http:// 和第一个句号之间输入的内容。
我希望那些重定向到
http://test.correct-domain.com/index.html?something=big
http://otherthing.correct-domain.com/index.html?something=else
这可能吗?我需要使用 RewriteRule 在 VirtualHost 语句中执行此操作。
类似这样,但我还需要捕获 http:// 和第一个句点之间的第一部分。
RewriteRule ^/(.*)$ http://??.correct-domain.com/ [R,L]
是的,很有可能。您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.inside\. [NC]
RewriteRule ^ http://%1.correct-domain.com%{REQUEST_URI} [NE,R=301,L]
%1
是 HOST_NAME
中第一部分的反向引用,在 RewriteCond
中被捕获。
我有以下内容:
http://test.inside/index.html?something=big
http://otherthing.inside/index.html?something=else
"test" 和 "otherthing" 可以是任何东西。我想捕获在 http:// 和第一个句号之间输入的内容。
我希望那些重定向到
http://test.correct-domain.com/index.html?something=big
http://otherthing.correct-domain.com/index.html?something=else
这可能吗?我需要使用 RewriteRule 在 VirtualHost 语句中执行此操作。
类似这样,但我还需要捕获 http:// 和第一个句点之间的第一部分。
RewriteRule ^/(.*)$ http://??.correct-domain.com/ [R,L]
是的,很有可能。您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.inside\. [NC]
RewriteRule ^ http://%1.correct-domain.com%{REQUEST_URI} [NE,R=301,L]
%1
是 HOST_NAME
中第一部分的反向引用,在 RewriteCond
中被捕获。