简体   繁体   English

通过301 htaccess / PHP重定向许多图像?

[英]Redirect many images via 301 htaccess / php?

An image gallery has 120,000 images. 图像库中有120,000张图像。 I want to change URL such as this: 我想更改如下网址:

/album_mod/upload/8c3d534a1451c87aca1fa710be6be8.jpg

to this, using a 301 redirect with a .htaccess file: 为此,使用带有.htaccess文件的301重定向:

/image/gallery/category-a8/imagename-i6282.jpg

However, my problem is that the original URL has no ID in the URL. 但是,我的问题是原始URL在URL中没有ID。 My idea is to: 我的想法是:

  1. Make a redirect for all JPG files to /redirect/ 将所有JPG文件重定向到/ redirect /
  2. Create a index.php in /redirect/ 在/ redirect /中创建index.php
  3. Cut of with php the filename for example "8c3d534a1451c87aca1fa710be6be8" 用php剪切文件名,例如“ 8c3d534a1451c87aca1fa710be6be8”
  4. Select in the DB for "8c3d534a1451c87aca1fa710be6be8". 在DB中选择“ 8c3d534a1451c87aca1fa710be6be8”。
  5. Take the category and the image name. 取类别和图像名称。
  6. Build the new string like: 构建新字符串,如下所示:
/image/gallery/category-a8/imagename-i6282.jpg

In this way I have two 301 redirects. 这样,我有两个301重定向。 Is there a better way? 有没有更好的办法?

You can do invisible rewrite to .php with this .htaccess : 您可以使用.htaccess.php无形重写:

RewriteEngine on 
RewriteRule ^album_mod/upload/(.+)\.jpg$ /redirect/index.php?file=$1 [L]

And after that you can do only one 301 redirect, with the right new name. 之后,您只能使用正确的新名称执行一次301重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM