【发布时间】:2013-06-13 20:26:56
【问题描述】:
我正在尝试重定向如下所示的 URL: http://getdotastats.com/sig/28755155.png
对于一个看起来像这样的人: http://getdotastats.com/sig/?aid=28755155
第一个 URL 是不存在的虚构 URL。
我想出的正则表达式如下。你能看看如何改进它。我缺乏形成正则表达式的必要知识,所以我只是让它匹配组,并忽略我不需要的那些。
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)sig/(.*)\.(.*)$ index.php?aid=$2 [NC,L]
我可以将上述内容放在特定目录 (/sigs) 中的 .htaccess 中,还是主 vhost 文件中需要额外的指令?
感谢您的帮助!
编辑:感谢futuretelmatics。使用下面的 .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule testpage\.html http://www.google.com [R]
RewriteRule ^/sig/([0-9]+\.(?:gif|png|jpg))$ index.php?aid=$1 [NC,L]
testpage重定向到google,但是图片重定向抛出如下错误。
The requested URL /sig/28755155.png was not found on this server.
我们必须靠近。 _
Vhost 看起来像:
DocumentRoot /home/www-dota2
<Directory /home/www-dota2/>
Options Indexes MultiViews +SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
allow from all
</Directory>
【问题讨论】:
标签: apache mod-rewrite dynamic-image-generation