问题描述
限时送ChatGPT账号..基于此线程:用于 .htaccess 重定向的正确正则表达式防止盗链
我在问一个更有针对性的问题(盗链已解决).
I am asking a more focused question (hotlinking is solved).
我正在做一个图像宿主项目并且正在编码图像名称.我需要为用户提供一个短网址来访问他们的图片.以下内容应在内部重定向:
I am doing an image host project and am encoding image names. I need to provide a short url for the users to access their images. The following should be internally redirected:
domain/hsh1h.jpg(或其他图片扩展名)
domain/hsh1h
domain/hsh1h.jpg (or other images extensions)
domain/hsh1h
这些将在内部重定向到:
domain/image.php?query=hsh1h.jpg
domain/image.php?query=hsh1h
These would be internally redirects to:
domain/image.php?query=hsh1h.jpg
domain/image.php?query=hsh1h
问题是不应重定向以下网址:
The issue is that the following url's should not be redirected:
domain/admin
domain/admin/index.php
domain/admin
domain/admin/index.php
我很抱歉之前创建了一个令人困惑的话题,非常感谢大家的帮助!
I apologize for creating a confusing topic earlier and thank you all so much for your help!
推荐答案
尝试:
# these rules ensure you aren't clobbering legit requests (like to image.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# just in case, exclude the admin directory
RewriteCond %{REQUEST_URI} !^/admin
# rewrite
RewriteRule ^(.*)$ image.php?query=$1 [L]
这篇关于.htaccess 内部重定向和 url 缩短的正确正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论