.htaccess 内部重定向和 url 缩短的正确正则表达式

编程入门 行业动态 更新时间:2024-10-23 19:34:17
本文介绍了.htaccess 内部重定向和 url 缩短的正确正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-20 00:12:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/972695.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   正确   正则表达式   htaccess   url

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!