3

我们正在改变用户在他们的博客中嵌入图像的方式,但我需要确保之前嵌入的图像仍然可以显示。

我正在尝试将旧图像嵌入链接重定向到静态图像或单个旧图像嵌入处理文件。我正在使用 mod_rewrite,但似乎我失败了。令人惊讶的是,我设法拼凑出一个防止盗链的功能性规则集。

不过,我在将遗留嵌入重定向到单个遗留处理程序时遇到了一些困难。此规则属于热链接集[L],因此仅在嵌入请求不是热链接的结果时才应评估。

这是我尝试将所有请求重定向到任何文件,例如gp[2]?.php[5]?\?p=(.*)

    RewriteRule %{REQUEST_FILENAME} gp[2]?\.php[5]?(.*)=(.*)$ [NC]
    RewriteRule gp[2]?\.php[5]?(.*)=(.*)$ /legacy/gp.php5$1=$2 [L]

但它不起作用,我只是得到了我美妙的 404 页面。

一些示例请求:

http://ecpod.com/includes/gp.php5?p=cfcfbfbe5d9d63eab4a3e784bd30cfe016fcfcfbfbe5d9d6a19ebc57139d56bb
http://www.ecpod.com/includes/gp.php5?p=928e3888a526b462b684aea5609016f928e3888a585d0963ac4ebb335a522e09
http://www.ecpod.com/includes/gp2.php?p=cfcfbfbe5d9d63eab4a3e784bd30cfe016fcfcfbfbe5d9d6a19ebc57139d56bb

我的目标是提出任何看起来像这些示例之一的请求:

http://ecpod.com/legacy/gp.php?p=HASH

感谢您的任何帮助。

编辑

旧版 url具有gp|gp2,php|php5和一个长度为 n 的查询字符串。它们可能不一定在includes目录中。我知道,这很混乱而且很可怕。现在图像嵌入的处理方式有所不同,这种情况永远不会再发生。

日志

RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5 [NC,L]

192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (3) [perdir /site/http/web/] add path info postfix: /site/http/web/includes -> /site/http/web/includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/includes/gp.php -> includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (3) [perdir /site/http/web/] applying pattern '^/(includes/)?gp2?\.php5?$' to uri 'includes/gp.php'
192.168.1.4 - - [06/Sep/2010:14:44:27 +1200] [www.ecpod-dev.dev/sid#2b7d543aa390][rid#2b7d68ec65a8/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes

RewriteCond %{QUERY_STRING} (^|&)(p=[^&]+)(&|$) [NC]
RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5?%2 [NC,L]

192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (3) [perdir /site/http/web/] add path info postfix: /site/http/web/includes -> /site/http/web/includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/includes/gp.php -> includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (3) [perdir /site/http/web/] applying pattern '^/(includes/)?gp2?\.php5?$' to uri 'includes/gp.php'
192.168.1.4 - - [06/Sep/2010:14:43:53 +1200] [www.ecpod-dev.dev/sid#2b8a2ad73400][rid#2b8a2b0ed438/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes


RewriteRule /gp2?\.php5?$ /legacy/gp.php5 [NC,L]

192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (3) [perdir /site/http/web/] add path info postfix: /site/http/web/includes -> /site/http/web/includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/includes/gp.php -> includes/gp.php
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'includes/gp.php'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (2) [perdir /site/http/web/] rewrite 'includes/gp.php' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642705a8/initial] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642756c0/initial/redir#1] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b1264277fa8/initial/redir#2] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427a7e8/initial/redir#3] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427cfe0/initial/redir#4] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b126427f948/initial/redir#5] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c3048/initial/redir#6] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c5800/initial/redir#7] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642c81f0/initial/redir#8] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cad80/initial/redir#9] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (3) [perdir /site/http/web/] strip per-dir prefix: /site/http/web/legacy/gp.php5 -> legacy/gp.php5
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (3) [perdir /site/http/web/] applying pattern '/gp2?\.php5?$' to uri 'legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (2) [perdir /site/http/web/] rewrite 'legacy/gp.php5' -> '/legacy/gp.php5'
192.168.1.4 - - [06/Sep/2010:14:45:37 +1200] [www.ecpod-dev.dev/sid#2b1256a153b0][rid#2b12642cd840/initial/redir#10] (1) [perdir /site/http/web/] internal redirect with /legacy/gp.php5 [INTERNAL REDIRECT]

外部<Directory>

http://www.ecpod-dev.dev/includes/gp.php?p=ff2287e8bb45572e38304afa184ba1a464016fff2287e8bb45572e0606111e7a

RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5 [NC,L]

192.168.1.4 - - [06/Sep/2010:23:46:54 +1200] [www.ecpod-dev.dev/sid#2ac33a5a83d0][rid#2ac34f0c4608/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes

RewriteCond %{QUERY_STRING} (^|&)(p=[^&]+)(&|$) [NC]
RewriteRule ^/(includes/)?gp2?\.php5?$ /legacy/gp.php5?%2 [NC,L]

192.168.1.4 - - [06/Sep/2010:23:47:47 +1200] [www.ecpod-dev.dev/sid#2b02af320470][rid#2b02bcb7b688/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes

RewriteRule /gp2?\.php5?$ /legacy/gp.php5 [NC,L]

192.168.1.4 - - [06/Sep/2010:23:48:45 +1200] [www.ecpod-dev.dev/sid#2aea076a73b0][rid#2aea14f025a8/initial] (1) [perdir /site/http/web/] pass through /site/http/web/includes
4

2 回答 2

2

测试模式的输入RewriteRule将不包含查询字符串,因此对其进行测试将阻止规则匹配和应用。

考虑到这一点,我们可以将规则修改为如下所示:

RewriteRule ^(includes/)?gp2?\.php5?$ /legacy/gp.php5 [NC,L]

假设查询字符串已经是您想要的格式,我们可以mod_rewrite通过在我们的重写中不指定替换来自动附加它。

如果您不确定查询字符串是否始终为 just p=HASH,并且希望保证它适用于目标脚本,我们可以扩展规则块以考虑到这一点,p在查询字符串中查找参数并替换仅包含该部分的现有查询字符串:

RewriteCond %{QUERY_STRING} (^|&)(p=[^&]+)(&|$) [NC]
RewriteRule ^(includes/)?gp2?\.php5?$ /legacy/gp.php5?%2 [NC,L]

根据Roland Illig 的评论,您还可以执行以下操作以减少对文件所在目录的限制:

RewriteCond %{REQUEST_URI} !^/legacy/
# Input to RewriteRule in .htaccess never has a leading slash, so make sure
# we're at the beginning or there was a slash before the filename
RewriteRule (^|/)gp2?\.php5?$ /legacy/gp.php5 [NC,L]

编辑:更改规则以反映如何定义它们httpd.conf而不是.htaccess.
编辑: ...然后再改回来。

于 2010-09-03T06:14:43.500 回答
0

这应该这样做:

RewriteRule ^\/includes\/gp\.php5?\?p=([a-f,0-9]{64})$ /legacy/gp.php?p=$1

于 2010-09-03T03:54:55.010 回答