2015-03-19 47 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