在内部将子域图像重写为主图像

时间:2013-07-19 18:53:19

标签: .htaccess rewrite

需要在内部重写test.example.com/images/*至example.com/images / *

test.example.com的位置是文件结构中的/ sub_ds / test /。

希望这是有道理的。目前链接到子域中的/images/test.jpg会在test.example.com/images/test.jpg中查找文件,这显然不存在,这就是我正在寻找重写的原因。

增加:

当前的共享:

选项+ SymLinksIfOwnerMatch

# BEGIN rewrites
RewriteEngine On

# Externally redirect client requests for example.com/sub_ds/<subdomain>/<URLpath> to <subdomain>.example.com/<URLpath>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /sub_ds/
RewriteRule ^sub_ds/([^/]+)/(.*)$ http://$1.example.com/$2 [R=301,L]

# Externally redirect client requests for www.[subdomain].example.com/sub_ds/<subdomain>/<URLpath> to <subdomain>.example.com/<URLpath> 
RewriteCond %{HTTP_HOST} ^www\.([a-z0-9-]+)\.example\.com
RewriteRule ^sub_ds/([^/]+)/(.*)$ http://$1.example.com/$2 [R=301,L]

# Externally redirect 'secure' subdomain to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^secure\.
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Externally redirect non 'secure' subdomain to http
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^secure\.
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Externally redirect index.(php|html?) in any location, preserving parameters, to location root
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /phpsite/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]*/)*)index\.(php|html?)(\?[^\ ]*)?\ HTTP
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L]

# BEGIN non-www to www
RewriteCond %{HTTP_HOST} !^(([a-z0-9][-a-z0-9]+)\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Internally rewrite <subdomain>.example.com/<URLpath> to example.com/sub_ds/<subdomain/<URLpath>
RewriteCond $1 !^sub_ds/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /sub_ds/%1/$1 [L]

目标...使test.example.com/images/*指向example.com/images / *

子域名实际上位于root用户的子文件夹中(通常用于大多数设置)。因此,测试子域实际位于/ sub_ds / test /

1 个答案:

答案 0 :(得分:0)

试试这段代码:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteRule ^images/(.*)$ http://example.com/sub_ds/test/images/$1

第二个链接检查主机是否正好是example.com(^表示主机名的开头和$结尾)。第一行检查url是否以images /开头重写。