I have 2 subdomains www.example.com
and static.example.com
and they both read the files on the same folder. So:
https://static.example.com/privacy
I see the same that I see on https://www.example.com/privacy
https://www.example.com/src/file.js
I see the same that I see on https://static.example.com/src/file.js
.htaccess
file.I want is to redirect any request of an image, video, js or css file from www
to static
and any other file type from static
to www
.
That way, if I go to https://static.example.com/privacy
I should be redirected to https://www.example.com/privacy
And, if I go to https://www.example.com/src/file.js
I see the same the is on https://static.example.com/src/file.js
You can do something like the following:
# Identify static resources - set an environment variable
SetEnvIf Request_URI "(?i)\.(jpg|png|gif|mpg|mp4|wmv|js|css)$" STATIC_RESOURCE
# Redirect static resources to static subdomain
RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{ENV:STATIC_RESOURCE} =1
RewriteRule \.([\w]{2,4})$ https://static.example.com%{REQUEST_URI} [R=301,L]
# Redirect "other" requests to www
RewriteCond %{HTTP_HOST} ^static\.
RewriteCond %{ENV:STATIC_RESOURCE} ^$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
Although, I assume your site is already linking to the appropriate subdomain?
You could just force a 404 instead?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments