2015-03-19 59 views
1

我有以下几点:阿帕奇只改写域名不是主机名

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

“测试”和“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/$1 [R,L] 

回答

1

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

RewriteEngine On 

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

%1是背参考第一部分中HOST_NAMERewriteCond被抓获。

+0

请帮我这个问题:http://stackoverflow.com/questions/29139699/apache-rewrite-only-domain-name-not-the-hostname/29141324#29141324 – 2015-03-19 10:04:07

+0

@Jocker:这是链接到当前的问题只要。 – anubhava 2015-03-19 10:07:56

+0

对不起,请帮助我这个问题:http://stackoverflow.com/questions/29140941/how-can-rewrite-url-using-htaccess-when-add-custom-foulder-name-in-url?noredirect = 1# comment46506001_29140941 – 2015-03-19 10:27:59