将 pdf 的外部请求重定向到嵌入 pdf 的页面
Redirect an external request of pdf to a page where the pdf is embedded
在使用 Joomla! 构建的网站中,我会将外部 pdf 请求重定向到使用 iframe 或对象元素嵌入 pdf 的页面。
我尝试通过 htaccess 进行操作,但它不起作用。 HTTP_REFERER 好像不太行。好像把内嵌pdf的请求当成外部请求处理了。
当我请求 mywebsite.com/pdf/filename.pdf 时,我被重定向到 mywebsite.com/filename 而且嵌入的 pdf 本身也被重定向到 mywebsite.com/filename 无限循环!
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^mywebsite\.com [NC]
RewriteRule ^pdf/\filename\.pdf$ http://website.com/filename [R=300,L]
这里是嵌入pdf的html代码:
<object data="/pdf/filename.pdf" type="application/pdf">
<p>This browser does not support PDFs.</p>
</object>
有没有人可以帮助我了解问题所在?
如何将 pdf 的外部请求重定向到嵌入 pdf 的页面?
谢谢!
因为 HTTP_REFERER
包含协议 (http://
),您不能使用 ^
。或者需要添加。
试试:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !mywebsite\.com [NC]
RewriteRule ^pdf/filename\.pdf$ http://website.com/filename [NC,R=302,L]
或者:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://mywebsite\.com [NC]
RewriteRule ^pdf/filename\.pdf$ http://website.com/filename [NC,R=302,L]
在使用 Joomla! 构建的网站中,我会将外部 pdf 请求重定向到使用 iframe 或对象元素嵌入 pdf 的页面。
我尝试通过 htaccess 进行操作,但它不起作用。 HTTP_REFERER 好像不太行。好像把内嵌pdf的请求当成外部请求处理了。
当我请求 mywebsite.com/pdf/filename.pdf 时,我被重定向到 mywebsite.com/filename 而且嵌入的 pdf 本身也被重定向到 mywebsite.com/filename 无限循环!
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^mywebsite\.com [NC]
RewriteRule ^pdf/\filename\.pdf$ http://website.com/filename [R=300,L]
这里是嵌入pdf的html代码:
<object data="/pdf/filename.pdf" type="application/pdf">
<p>This browser does not support PDFs.</p>
</object>
有没有人可以帮助我了解问题所在?
如何将 pdf 的外部请求重定向到嵌入 pdf 的页面?
谢谢!
因为 HTTP_REFERER
包含协议 (http://
),您不能使用 ^
。或者需要添加。
试试:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !mywebsite\.com [NC]
RewriteRule ^pdf/filename\.pdf$ http://website.com/filename [NC,R=302,L]
或者:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://mywebsite\.com [NC]
RewriteRule ^pdf/filename\.pdf$ http://website.com/filename [NC,R=302,L]