Forum Moderators: phranque
# 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]
# 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]
but it will prove troublesome when actually designing the websites as the pictures will not be visually available
perhaps not enough people have the need for this type of setup?
then allow both http and https on that subdomain?
This still brings up the issue of dupe content with secure/non-secure of all images, css, and js though
# If the host is assets.example.com or empty
# and the extension is .gif .jpg .js end the rewriting
RewriteCond %{HTTP_HOST} ^(assets\.example\.com)?$
RewriteRule \.(gif|jpg|js)$ - [L]
# If the host is NOT assets.example.com or empty
# redirect to the assets.example.com sub
RewriteCond ${HTTP_HOST} !^(assets\.example\.com)?$
RewriteRule \.(gif|jpg|js)$ http://assets.example.com%{REQUEST_URI} [R=301,L]
I am not sure if calling the assets from the subdomain would benefit from the speed increase in parallel (maybe not the right word, but I know you can serve more content quickly when using multiple domains/locations) downloading or not since there would be a redirect called on each.
One the first condition is out of the way-- "the host IS assets.example.com or nothing"-- and you've met your [L] flag, is there any possible circumstance where the condition in the follow-up rule would NOT be met? Seems like the condition wouldn't even be necessary.