mod_rewrite用于复杂的子域重定向

时间:2015-02-05 22:13:41

标签: regex wordpress apache .htaccess mod-rewrite

这些是我目前的指令,用于将子域HTTP请求重定向到具有路径的域。

RewriteCond %{HTTP_HOST} ^blog.website.com
RewriteRule ^(.*)$ http://website.com/blog [L]

但是,此网站是已发布社交媒体链接的网站的新版本。这些链接具有现在已断开的图像URL,因为URL现在指向不同的服务器。此后,图像已被迁移,并且所述图像的路径已保留在新服务器上。鉴于此,我需要重写我的指令来解释这些遗留链接。

当网址没有路径或网址的第一个参数 /wp-content/时,我需要编写重写网址 的条件。

我必须制定区分这3种网址模式的条件和规则:

http://blog.website.com 
    -> http://website.com/blog
http://blog.website.com/wp-content/year/month/image.jpg 
    -> http://website.com/wp-content/year/month/image.jpg
http://blog.website.com/entry-url-title 
    -> http://website.com/blog/entry-url-title

1 个答案:

答案 0 :(得分:0)

当然,在我的朋友的帮助下,这最终是我能够做到的。

RewriteCond %{HTTP_HOST} blog.website.com
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.*) http://website.com/blog [R=301,L]

RewriteCond %{HTTP_HOST} ^blog.website.com
RewriteCond %{REQUEST_URI} !wp-content
    RewriteRule ^(.*) http://website.com/blog/%{REQUEST_URI} [R=301,NC,L] 

RewriteCond %{HTTP_HOST} ^blog.website.com
RewriteCond %{REQUEST_URI} wp-content
    RewriteRule ^(.*) http://website.com/%{REQUEST_URI} [R=301,NC]
相关问题