0

我已经搜索了几个小时的教程来学习如何重写包含“?”的图像路径 url。

我的图像如下所示:

<img src="/index.php?rex_resize=600w__/imageName.jpg" >

为了缓存所有图像,我必须/想要删除这个“?” 从字符串。

这是我使用的规则:

RewriteRule ^rex_resize/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)\.(gif|jpg|jpeg|png)$ /index.php?$1/$2.$3 [NC]

这是我的 .htaccess 中的所有内容,里面有我的 rewriteRule:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteRule ^rex_resize/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)\.(gif|jpg|jpeg|png)$ /index.php?$1/$2.$3 [NC]

RewriteRule ^sitemap\.xml$ index.php?rexseo_func=googlesitemap [NC,L]
RewriteRule ^robots\.txt$ index.php?rexseo_func=robots [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^redaxo/.*
RewriteCond %{REQUEST_URI} !^files/.*
RewriteCond %{REQUEST_URI} !^google(.*).html*
RewriteRule ^((.|\r|\n)+)/? index.php?params=$1 [L,NC]
</IfModule>

但是由于我从未学习过正确的 RewriteRules,因此我无法从这个 RewriteRule 中得到匹配,而且我对此的了解非常有限。

对于一些帮助,我很感激:)

4

1 回答 1

0

您需要找出在您的 URL 中匹配的模式,以了解您必须将当前请求重写为您的图像脚本。

根据您的帖子和评论,假设模式是:

所有 URI...

  • 文件开头/
  • 以网络图像后缀(gifjpgpng)结尾
  • 那些之间

把它写成一个正则表达式然后你就完成了:

  • / : URI 的开头
  • files/ : 我们的假目录
  • (.*):捕获任何东西(将存储在 $1 中)
  • \。: 一个点
  • (gif|jpg|jpeg|png):文件后缀(将存储在 $2 中)
  • $ : URI 结束

重写规则:

RewriteRule ^/files\/(.*)\.(gif|jpg|jpeg|png)$ index.php?rex_resize=$1.$2 [NC,L]

例子 :

传入请求:

/files/600w/imageName.jpg

Mod_Rewrite 后的请求:

/index.php?rex_resize=600w/imageName.jpg

请注意,您的示例显示了对 /index.php 的重定向(以斜杠开头),当您使用 .htaccess 文件时它应该不起作用(它仅在 whost 配置中有规则时才起作用)

于 2013-08-13T16:07:26.367 回答