简体   繁体   中英

Nginx Friendly URL File Extension

I got my nginx.conf file:

location ~*  \.(jpg|jpeg|png|gif|ico|css|js|swf)$ {
   expires 7d;
}

location /
{
    try_files $uri $uri/ @rewrite
}


location @rewrite
{
    rewrite ^/([a-zA-Z0-9_-]+)?\/?([a-zA-Z0-9_-]+)?\/?([a-zA-Z0-9_-]+)?\/?([a-zA-Z0-9_-]+)?\/?([a-zA-Z0-9_-]+)?\/?([a-zA-Z0-9_-]+)?$ /index.php?a=$1&b=$2&c=$3&d=$4&e=$5&f=$6 break;
}

I want to replace friendly-url (generated by php file) link with seo optimised one.

https://example.com/gallery/basic-friendly-url-here/photoid

File extension is required by search engine, so I need to make it look like this:

https://example.com/gallery/basic-friendly-url-here/photoid.png

Unfortunately, I can't do it this way, because nginx throws 404 error.

Any ideas how to redirect link https://example.com/gallery/ * into executable php file located in /vendor/mindgoner/script.php and handle seo url as GET parameter, instead of path?

Ok, if there are no physical directory named gallery under your web server root directory, you can use the following:

location ^~ /gallery/ {
    rewrite ^/gallery/(.*) /index.php?gallery_item=$1 last;
}

Then the requested filename will be available inside your index.php as the $_GET['gallery_item'] .

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