質問

i want to redirect all hotlinked images to one dummy image.

i applied htaccess code for this purpose, but it is only redirecting 404(not found) images

means the hotlinked images with correct links are not being redirected.

i also have applied a redirect for non-www to www version, think this redirect is causing some conflict with hotlinked redirect code

here is the code

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301]
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f

RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite/.*$ [NC]
RewriteRule \.(gif|jpg|png) http://www.mysite.com/temp/aa.jpg [R,L]
役に立ちましたか?

解決

A modification like this one should work:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^.*/aa.jpg$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com/?$ [NC]
RewriteRule ^.*\.(gif|jpg|png)$ http://www.mysite.com/temp/aa.jpg [R=301,L]

他のヒント

Well, you explicitly exclude rewriting of requests to files that do exist with this condition:

RewriteCond %{REQUEST_FILENAME} !-f

I actually I am not sure if you really want to redirect all clients for every single image to another domain name. That means you double the http requests required for the client.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top