Apache 只重写域名而不是主机名



>我有以下内容:

http://test.inside/index.html?something=big
http://otherthing.inside/index.html?something=else
">

测试"和"其他事物"可以是任何东西。我想捕捉在 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/$1 [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中被捕获。

最新更新