.htaccess 图像到网页重定向?
是否有一个 .htaccess 脚本可以用来将图像的 url 重定向到实际的网页?
当有人通过地址栏输入以下内容访问图像时,我该怎么做: http://www.sitename.com/uploads/192-file-name-here.jpg 或其他扩展,例如 http://www.sitename.com/uploads/235-file-name -here.png
它会将用户重定向到网页: http://www.sitename.com/view/192-file-name-这里/
不过,我仍然希望能够将图像放置在整个网站和外部网站上的图像标签中。
RewriteCond %{HTTP_REFERER} !^https?:\\www\.sitename\.com
RewriteCond %{REQUEST_URI} (.*)\.jpg$
RewriteRule images/(\d+)\.jpg http://www.sitename.com/view/$1.html [L,R=301]
RewriteCond %{HTTP_REFERER} ^$
可以修改/重写它来执行我的功能吗?
Is there a .htaccess script I can use to redirect the url of an image to an actual web page?
What can I do to make it so when someone accesses an image via their address bar by typing in: http://www.sitename.com/uploads/192-file-name-here.jpg
or other extensions like
http://www.sitename.com/uploads/235-file-name-here.png
It will instead redirect the user to the web page:
http://www.sitename.com/view/192-file-name-here/
I want to still be able to place the images in image tags across the site and on external sites though.
RewriteCond %{HTTP_REFERER} !^https?:\\www\.sitename\.com
RewriteCond %{REQUEST_URI} (.*)\.jpg$
RewriteRule images/(\d+)\.jpg http://www.sitename.com/view/$1.html [L,R=301]
RewriteCond %{HTTP_REFERER} ^$
Can this be modified/re-written to perform my function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其放入您的
.htaccess
中,它将重定向用户直接发送的所有请求。注意:正如您提到的,其他网站可以将您的图像放入其页。
put this in your
.htaccess
, it will redirect all requests that are sent directly by user.Note: Other sites,as you mentioned can put your images in their pages.
是的,您始终可以使用
.htaccess
将图像重定向到网页或任何内容。但
images/(\d+).*\.jpg
可能会更好。Yes you can always redirect images to a webpage or anything using
.htaccess
.But
images/(\d+).*\.jpg
may be better.