Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have pictures on a path looking like this:

/0/1/2/3/4/01234/screenshots/1.jpg

The URL to access it looks like this:

/static/0/1/2/3/4/01234/screenshots/1.jpg

I'd like it to look like this:

/0/1/2/3/4/01234/a-desc-of-the-picture/screenshots/1.jpg

Or something similar. The goal is to have the keywords in the URL for SEO.

But would like to tell nginx to serve

/0/1/2/3/4/01234/screenshots/1.jpg

When he sees:

/0/1/2/3/4/01234/a-desc-of-the-picture/screenshots/1.jpg

I don't want it to redirect the user to the proper URL, I just want it to do the mapping internally.

Is it possible ? How can I achieve this ?

I've seen something similar here, but I can't find a way to apply it to my case. Something noob friendly would be much appreciated.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Assuming you've got a base path that's regexable, you can do something like:

location ~ ^/static/(././././.....)/[^/]+/(.*)$ {
    alias /location/on/filesystem/$1/$2;
}

Nginx's alias directive is more flexible than Apache's equivalent.

share|improve this answer
    
There is typo. Exclamation mark "!" in location statement should be replaced with tilda "~". –  AlexD Jul 18 '11 at 10:47
    
Thanks for that. You can edit directly though, rather than dropping in a comment. –  womble Jul 18 '11 at 10:48
    
I can't. It prevents me from doing edits wich less than 6 characters long and I don't want to mess with other parts to overcome this limit. –  AlexD Jul 18 '11 at 10:50
    
How odd... I never realised there was a "minimum edit limit". Oh well, thanks for letting me know anyway. –  womble Jul 18 '11 at 10:59
    
Cool thanks. Can you show me how to do that with lighttpd too ? I changed the title. –  e-satis Jul 18 '11 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.