在我的服务器上,我使用 TimThumb 作为调整图像大小的插件,它工作得很好,除非我尝试在我的电子邮件内容中使用它。
Google Gmail 将此https://example.com/thumb.php?sr+c=
作为src
属性输出(注意加号)。
我在这里读到这是因为查询。
那么我怎样才能使用.htaccess
重写我的 url 并/thumb.php?src=
用 a删除/src/
呢?
这是它看起来链接到图像的方式:
https://example.com/thumb.php?src=example.jpg
这就是我需要的
https://example.com/src/example.jpg
这是我现在的.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^welcome/([^/]+)/?$ index.php?a=welcome&filter=$1 [NC,QSA,L]
RewriteRule ^explore/([^/]+)/?$ index.php?a=explore&filter=$1 [NC,QSA,L]
RewriteRule ^page/([^/]+)/?$ index.php?a=page&filter=$1 [NC,QSA,L]
RewriteRule ^(([^/]+)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L,QSA]
index.php
并且thumb.php
都在根文件夹中
更新
我尝试将此行添加到我的.htaccess
并访问https://example.com/src/example.jpg
但它再次不起作用,在这种情况下它重定向到“欢迎”页面。
RewriteRule ^src/([^/]*)$ /thumb.php?src=$1 [L]
第二次更新
我也试过这个:
RewriteRule ^src/([^/]+)/?$ thumb.php?src=$1 [NC,QSA,L]
同样,它无法https://example.com/src/example.jpg
重定向到我的“欢迎”页面。
这就是我的 .htaccess 现在的样子
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^welcome/([^/]+)/?$ index.php?a=welcome&filter=$1 [NC,QSA,L]
RewriteRule ^explore/([^/]+)/?$ index.php?a=explore&filter=$1 [NC,QSA,L]
RewriteRule ^page/([^/]+)/?$ index.php?a=page&filter=$1 [NC,QSA,L]
RewriteRule ^src/([^/]+)/?$ thumb.php?src=$1 [NC,QSA,L]
RewriteRule ^(([^/]+)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L,QSA]
第三次更新
thumb.php
这就是我构建 src 查询的方式
$_GET['src'] = 'https://s3-eu-west-1.amazonaws.com/bucket1'.'/'.$_GET['src'];
我无法弄清楚这里出了什么问题。
第四次更新
根据 Vladimir Cvetic 的回答,我尝试了这个:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^src/(.*)$ /thumb.php?src=$1 [L,QSA]
RewriteRule ^welcome/([^/]+)/?$ index.php?a=welcome&filter=$1 [NC,QSA,L]
RewriteRule ^explore/([^/]+)/?$ index.php?a=explore&filter=$1 [NC,QSA,L]
RewriteRule ^page/([^/]+)/?$ index.php?a=page&filter=$1 [NC,QSA,L]
RewriteRule ^src/([^/]+)/?$ thumb.php?src=$1 [NC,QSA,L]
RewriteRule ^(([^/]+)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L,QSA]
再次它不起作用,这是错误:
`The 't' parameter is not set.`
但这很奇怪,因为我将 't' 参数条件设置为空,如下所示:
if(!empty($_GET['t'])) {
if($_GET['t'] == 'a') {
$type = 'uploads/avatars';
$width_list = array(25, 35, 50, 70, 100, 112, 150, 200, 300);
$height_list = array(25, 35, 50, 70, 100, 112, 150, 200, 300);
} elseif($_GET['t'] == 'b') {
$type = 'uploads/backgrounds';
...
} else {
exit('Invalid parameter value');
}
} else {
$_GET['t'] == 'a';
$type = 'uploads/avatars';
$width_list = array(25, 35, 50, 70, 100, 112, 150, 200, 300);
$height_list = array(25, 35, 50, 70, 100, 112, 150, 200, 300);
}
确实,如果我访问https://example.com/thumb.php?src=example.jpg
,我可以正确看到头像图像