如何使用“ .htaccess”删除图像的URL子文件夹?

时间:2019-05-18 05:35:43

标签: php wordpress .htaccess

如何从URL中删除子文件夹名称?

例如:

  1. mywebsite.com/wp-contents/uploads/2019/02/image.jpg
  2. mywebsite.com/wp-contents/uploads/user/demo/2019/02/image2.jpg

然后使用没有子文件夹名称的相同URL:

  1. mywebsite.com/uploads/image.jpg
  2. mywebsite.com/uploads/image2.jpg

信息:我只能使用.htaccess来实现这一目标。

1 个答案:

答案 0 :(得分:0)

在您的.htaccess文件中尝试使用此规则

RewriteEngine On
RewriteRule ^uploads\/image\.jpg$ /wp-contents/uploads/2019/02/image.jpg [L]
RewriteRule ^uploads\/image2\.jpg$ /wp-contents/uploads/user/demo/2019/02/image2.jpg [L]

所有/uploads/image***.jpg到/wp-contents/uploads/2019/02/image***.jpg的另一条规则

RewriteEngine On
RewriteRule ^uploads\/(.*)$ /wp-contents/uploads/2019/02/$1 [L]