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

时间:2015-03-19 08:12:24

标签: apache .htaccess mod-rewrite

我有以下内容:

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

"测试"和" othe"可以是任何东西。我想捕捉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]

1 个答案:

答案 0 :(得分:1)

是的,这是非常有可能的。您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^.]+)\.inside\. [NC]
RewriteRule ^ http://%1.correct-domain.com%{REQUEST_URI} [NE,R=301,L]

%1HOST_NAMERewriteCond中第一部分的后向引用。

相关问题