chr*_*ris 1 apache .htaccess mod-rewrite image
我曾经在我的域名上建立并运行过一个网站,但后来我将其删除了。然而,在该网站中,我有一些与其他网站共享的特定图像。
自从我访问该域的日志以来已经有一段时间了,我意识到大约有 2 打图像出现为 404,并且我将它们识别为共享图像。我想要做的是将这些图像放在我的另一个域中,并且对这些图像的任何请求都会使用图像现在所在的其他域 url 进行重写。
是否可以在一对一的基础上指定图像并让它们指向另一个域上的对应部分?我见过这样的情况,人们没有那么挑剔,但对我想做的事情却毫无兴趣。
是的,您可以使用 .htaccess 来做到这一点。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteRule ^img/path/to/file1.jpg$ http://newdomain.com/new/path/to/file1.jpg [L,R=301]
RewriteRule ^img/path/to/file2.jpg$ http://newdomain.com/other/new/path/to/file2.jpg [L,R=301]
RewriteRule ^img/path/to/(file3.jpg|file4.jpg)$ http://newdomain.com/typical/new/path/to/$1 [L,R=301]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
考虑到http://olddomain.com/img/path/to/file1.jpg是图像文件之一,并且 .htaccess 位于 的文档根目录中olddomain.com,这应该可以完成这项工作。如果您无法将新旧文件名与某些正则表达式进行匹配,则需要RewriteRule为每个丢失的图像添加一行。
| 归档时间: |
|
| 查看次数: |
2027 次 |
| 最近记录: |