2011-12-16 63 views
0

我正在尋找將「存檔」的子域添加到單擊的URL以允許它們轉到新存檔站點而不是常規站點。您可以訪問該網站http://archives.thegatepost.com,並瞭解我想要做什麼。mod_rewrite將子域添加到URL

  1. 用戶訪問網站:#http://archives.thegatepost.com/archived06.html
  2. 用戶點擊鏈接查看:#http://www.thegatepost.com/news/GP_pgs1-4.pdf
  3. 重新寫入:#http://archives.thegatepost.com/news/GP_pgs1-4.pdf

    • 這需要能夠實現在.htaccess文件中

    • 不擔心301或類似的東西。如果它可以做SEO友好,所有更好,如果不是沒有損失。

我已經試過Apache mod_rewrite domain to subdomain?,並且它不工作:

RewriteEngine On 

RewriteCond %{http_host} ^thegatepost.com/archives [nc] 
RewriteRule ^(.*)$ http://www.thegatepost.com/archives/$1 [R=301,NC] 

RewriteCond %{HTTP_HOST} ^www\.thegatepost\archives\.com$ [NC] 
RewriteRule ^archives/([a-z0-9\-_\.]+)/?(.*)$ http://$1.thegatepost.com/archives/$2 [QSA,NC,R,L] 

回答

0

嘗試在.htaccess中的www.thegatepost.com域的根文件夾

RewriteEngine on 
RewriteBase/

#if request on www.gatepost.com 
RewriteCond %{HTTP_HOST} ^www\.thegatepost\.com$ [NC] 
#and for a resource in the /news/ directory 
RewriteCond %{REQUEST_URI} ^/news/ [NC] 
#redirect them to same resource on the archives.thegatepost.com 
RewriteRule (.*) http://archives.thegatepost.com/$1 [L,R=301]