Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx:删除部分url_Url_Nginx_Rewrite - Fatal编程技术网

Nginx:删除部分url

Nginx:删除部分url,url,nginx,rewrite,Url,Nginx,Rewrite,我正在为我的Nginx服务器寻找正确的重写规则。我想删除URL的特定部分 例如: example.com/assets/files--实际位置 到 example.com/files 及 example.com/assets/files/image.jpg 到 example.com/files/image.jpg 及 example.com/assets/themes/css/style.css 到 example.com/themes/css/style.css 我已经在谷歌上搜索过了,但是

我正在为我的Nginx服务器寻找正确的重写规则。我想删除URL的特定部分

例如:

example.com/assets/files--实际位置

example.com/files

example.com/assets/files/image.jpg

example.com/files/image.jpg

example.com/assets/themes/css/style.css

example.com/themes/css/style.css

我已经在谷歌上搜索过了,但是我发现所有的问候语都不适合我。我刚刚犯了大约500个错误


那么,我需要什么样的重写规则,我应该把它放在我的conf文件中的什么地方呢。谢谢大家!

根据您发布的相关信息。我可以看出您正在尝试重命名URL,而不更改文件的确切位置

要实现这一点,请在服务器指令中添加以下内容:

#Example : 
#Rewriting example.com/themes -> example.com/assets/themes
location /themes {
    rewrite ^/.* http://$server_name/assets/themes permanent;
}
location /files {
    rewrite ^/.* http://$server_name/assets/files permanent;
}
现在您的用户将打开例如:,服务器上的文件将放置在位置/var/www/。something…/example.com/assets/files/image.jpg


希望这有帮助……!:)

实际位置是磁盘上的路径。仍然不清楚您想要什么我这里有一个文件:example.com/assets/files/image.jpg,我希望它从URL中删除资产。这样做:example.com/files/image.jpg谢谢!如果我转到/files,就会被重定向到/assets/files。但是/files/image.png给了我一个404错误。我在这里发布了我的配置,如果它更容易解决的话。这个配置将我重定向到/assets/files/files/files/image.png给了我一个404。我忘记了wordpress的一个位置块。这会影响我的配置吗?新配置-->