Nginx友好URL文件扩展名



我得到了我的nginx.conf文件:

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;
}

我想替换友好的url(由php文件生成)链接与seo优化的一个。

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

文件扩展名是搜索引擎所要求的,所以我需要使它看起来像这样:

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

不幸的是,我不能这样做,因为nginx抛出404错误。

任何想法如何重定向链接https://example.com/gallery/*到可执行的php文件位于/vendor/mindgoner/script.php和处理seo url作为GET参数,而不是路径?

好的,如果在你的web服务器根目录下没有名为gallery的物理目录,你可以使用以下命令:

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

然后请求的文件名将在index.php中作为$_GET['gallery_item']可用。

最新更新