2

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.

1 Answer 1

4

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.

7
  • There is typo. Exclamation mark "!" in location statement should be replaced with tilda "~". Commented Jul 18, 2011 at 10:47
  • Thanks for that. You can edit directly though, rather than dropping in a comment. Commented Jul 18, 2011 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. Commented Jul 18, 2011 at 10:50
  • How odd... I never realised there was a "minimum edit limit". Oh well, thanks for letting me know anyway. Commented Jul 18, 2011 at 10:59
  • Cool thanks. Can you show me how to do that with lighttpd too ? I changed the title. Commented Jul 18, 2011 at 11:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.