mod_rewrite将子域附加到URL

时间:2011-12-16 18:43:51

标签: .htaccess mod-rewrite subdomain

我希望将“存档”的子域附加到点击的网址,以允许他们转到新的存档网站,而不是常规网站。您可以访问http://archives.thegatepost.com网站,了解我的目标。

  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友好,所有更好,如果不是没有损失。

  4. 我尝试了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]
    

1 个答案:

答案 0 :(得分:0)

www.thegatepost.com

的根文件夹中的.htaccess文件中尝试以下操作
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]