2012-02-14 74 views
0
RewriteCond %{HTTP_HOST} !^www\.DOMAIN\.com 
RewriteCond %{HTTP_HOST} ^(.*)\.DOMAIN\.com 
RewriteRule ^(.*)$ http://DOMAIN.com/FolderName/$1 [L] 

如果我鍵入SubDomain.DOMAIN.COM它將我重定向到DOMAIN.COM/Folder/罰款,但我不想瀏覽器地址欄中的網址更改爲DOMAIN.COM/Folder/,但保持爲SubDomain.DOMAIN.COM。SubDomain.DOMAIN.COM保留在瀏覽器地址欄中 - .htaccess/mod_rewrite

任何線索。

+0

您:(1)需要一幀/ IFRAME; OR(2)在重寫和mod_proxy中需要[P]標誌 – 2012-02-14 06:57:16

+0

@ J-16SDiZ mod_proxy在 – X10nD 2012-02-14 07:07:32

回答

1
RewriteCond %{HTTP_HOST} !^www\.DOMAIN\.com 
RewriteCond %{HTTP_HOST} ^(.*)\.DOMAIN\.com 
RewriteRule ^(.*)$ http://DOMAIN.com/FolderName/$1 [L] 

當一個重寫規則指向一個域,將出現一個明確的重定向。默認情況下是302重定向(臨時重定向)。

我建議你使用P(代理)標誌。爲此,mod_proxy應該啓用。

RewriteCond %{HTTP_HOST} !^www\.DOMAIN\.com 
RewriteRule ^(.*)$ http://DOMAIN.com/FolderName$1 [L,R=301] 

RewriteCond %{HTTP_HOST} ^(.*)\.DOMAIN\.com 
RewriteRule ^(.*)$ http://DOMAIN.com/FolderName/$1 [L,P] 

還記得設置ProxyReverse指令。

Context: server config, virtual host, directory 

所以,你不能在一個.htaccessProxyReverse

直接從:Proxying Content with mod_rewrite Apache Docs
考慮使用ProxyPassProxyPassMatch儘可能優先於mod_rewrite。

訪問本作如何的ProxyPasshttps://stackoverflow.com/a/9189447/858515

+0

工作就像一個魅力...謝謝... – X10nD 2012-02-14 07:39:15

+0

@Jean歡迎.. – ThinkingMonkey 2012-02-14 07:39:51

+0

包括選項FollowSymLinks在httpd.conf的幫助? – X10nD 2012-02-14 07:41:47

0

看重寫規則docs

Absolute URL 

If an absolute URL is specified, mod_rewrite checks to see whether the 
hostname matches the current host. If it does, the scheme and hostname 
are stripped out and the resulting path is treated as a URL-path. 
Otherwise, an external redirect is performed for the given URL. 

所以 - 嘗試使用直接的文件系統路徑:

RewriteCond %{HTTP_HOST} !^www\.DOMAIN\.com 
RewriteCond %{HTTP_HOST} ^(.*)\.DOMAIN\.com 
RewriteRule ^(.*)$ /path/to/domain.com/DocumentRoot/FolderName/$1 [L] 
+0

/path/to/domain.com/DocumentRoot/FolderName/是http://DomainName.com/FolderName。所以我會把它寫成 RewriteRule ^(。*)$/FolderName/$ 1 [L]? – X10nD 2012-02-14 07:08:32

+0

你可以試試。我不知道它是否會奏效。安全賭注是一個完整的文件系統路徑,如/ var/www/server/folder /。 – kupson 2012-02-14 07:24:57

相關問題