简体   繁体   中英

Apache Rewrite for images on subdomain

I have a webserver and a subdomain. All of my images are stored in /public/images within my site directory for www.mysite.com. However I have a separate site directory for testing beta.mysite.com however on this page with a different git branch all of my images are broken because I did not want to copy all of the images. Is it possible to say for all image requests or for all 404 requests try looking at mysite.com?

I have found an example on another questions

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

But since I am rather new to mod_rewrite im not sure what is going on or how to manipulate it to work for me.

You can use this rule in root .htaccess of beta subdomain:

RewriteEngine On

RewriteCond %{HTTP_HOST} =beta.example.com
RewriteRule ^(images/.+)$ http://example.com//public/$1 [L,NC,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM