将seo友好URL重定向到映射到domain.com的子域

时间:2011-08-13 20:15:48

标签: .htaccess

我正在尝试将seo友好网址重定向到映射到我的主域名的子域名,因此子域名实际上并不包含任何内容。它只是化妆品。

RewriteEngine on
RewriteBase /

ErrorDocument 404 /notfound.php

RewriteRule ^$ index.php [L]
RewriteRule ^videos/(.*)-([0-9]+).html /videos/r/$1/ [R=301,L]
RewriteRule ^watch/([^/\.]+)/([^/\.]+).html$ /videos/$2-$1.html [R=301,L]
RewriteRule ^video/([^/\.]+)-([0-9]+).html$ watch.php?id=$2 [L]
RewriteRule ^video/(.*)/([^/\.]+)-([0-9]+).html$ watch.php?id=$3 [L]

这会产生domain.com/video/seofriendyurl.html,我希望它重定向到subdomain.domain.com/video/seofriendlyurl.html。它只是化妆品。因此,如果我访问domain.com/video/seofriendyurl.html,我希望将其重定向到subdomain.domain.com/video/seofriendlyurl.html。

1 个答案:

答案 0 :(得分:1)

使用[R=301]时,建议使用FQDN 来自apache2 docs

  

使用http:// thishost [:thisport] /(使新URL成为URI)进行前缀替换以强制进行外部重定向。

所以你的RewriteRules将是

RewriteRule ^$ index.php [L]
RewriteRule ^videos/(.*)-([0-9]+).html http://subdomain.domain.com/videos/r/$1/ [R=301,L]
RewriteRule ^watch/([^/\.]+)/([^/\.]+).html$ http://subdomain.domain.com/videos/$2-$1.html [R=301,L]
RewriteRule ^video/([^/\.]+)-([0-9]+).html$ watch.php?id=$2 [L]
RewriteRule ^video/(.*)/([^/\.]+)-([0-9]+).html$ watch.php?id=$3 [L]
相关问题