正确的正则表达式的.htaccess内部重定向和URL缩短 [英] Proper regex for .htaccess internal redirect and url shortening

查看:260
本文介绍了正确的正则表达式的.htaccess内部重定向和URL缩短的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此线索:<一href="http://stackoverflow.com/questions/12394494/proper-regex-for-htaccess-redirect-and-$p$pvention-of-hotlinks">Proper的正则表达式的.htaccess重定向和热链接prevention

我问一个更集中的问题(盗链解决)。

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.com/hsh1h.jpg(或其它图像扩展)
domain.com/hsh1h

domain.com/hsh1h.jpg (or other images extensions)
domain.com/hsh1h

这些是内部重定向到:
domain.com/image.php?query=hsh1h.jpg
domain.com/image.php?query=hsh1h

These would be internally redirects to:
domain.com/image.php?query=hsh1h.jpg
domain.com/image.php?query=hsh1h

的问题是,下面的网址的不应被重定向:

The issue is that the following url's should not be redirected:

domain.com/admin
domain.com/admin/index.php

domain.com/admin
domain.com/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆