简体   繁体   中英

nginx Location regex for wordpress

I'm converting my site from .net to Wordpress, and an import has set the img reference to a lot of my pictures to urls starting with /2014/01/articlefiles , 2014/02/articlefiles , all the way back to 2003. etc.

All the pictures on the webserver is located in the same folder

/var/www/sharedfolders/indhold/articlefiles/

Is it possible to make a location that answers

/yyyy/mm/articlefiles/picturename.ext

(Where yyyy = any year & mm = any month in numbers.)

and points to /var/www/sharedfolders/indhold/articlefiles/picturename.ext

I tried a lot of different ways.

Tried this: ( Still no luck )

location ~ ^/(2003|2004|2005|2006|2007|2008|2009|2010|2011|2012|2013|2014)/(01|02|03|04|05|06|07|08|09|10|11|12)/articlefiles/(.*)
{
    alias /var/www/sharedfolders/articlefiles/$3;
}

I solved it my self.

location ~ ^/20[0-1][0-9]/[0-1][0-9]/articlefiles/?(.*) {
    alias /var/www/sharedfolders/indhold/articlefiles/$1;
     access_log off;
     log_not_found off;
            add_header Pragma public;
            add_header Cache-Control "max-age=31536000, public";
}

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