【问题标题】:Redirect raw .gif files to handler page via .htacces - my code doesn't work重定向原始 .gif 文件以通过 .htaccess 处理页面 - 我的代码不起作用
【发布时间】:2015-04-01 04:03:11
【问题描述】:

我有一个病毒图片网站,人们可以在其中查看有趣的 GIF。然而,reddit 上的很多人都在分享原始的 .gif 文件,而不是嵌入了 .gif 的页面。这很好 - 但我想将所有查看原始图像 .gifs 的人重定向到一个名为 shareraw.php 的处理程序页面(位于根目录中)。这个处理程序页面看起来完全一样 - 只是带有一个共享链接和按钮来查看网站的其余部分。

原始图像位置示例:http://gifsec.com/wp-content/uploads/GIF/2015/03/Scared-Reaction-Gif.gif

分享页面位置:http://gifsec.com/shareraw.php

这是我目前不工作的代码。当我转到原始 gif 时,什么也没有发生:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{HTTP_REFERER} !^http://(www\.)?gifsec.com\.com/ [NC]
RewriteCond %{REQUEST_URI} /uploads/GIF/.*\.gif$ [NC]
RewriteRule ^(.*)$ /shareraw.php?img=$1 [R,L]


## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

【问题讨论】:

  • 如果你想重定向到shareraw.php,你应该把它放在规则的前面。

标签: php .htaccess redirect server


【解决方案1】:

好的,我们将 gif 重定向到专用页面。该页面将如何呈现 gif?再次,使用 gif 文件?循环开始。

您可以使用 PHP 与 htaccess 的组合来实现它,但您必须更改所有位置的图像显示。 (虽然不是万无一失)

根据站点大小,可以估算工作量。

【讨论】:

    猜你喜欢
    • 2015-05-29
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多