Forum Moderators: phranque
ErrorDocument 404 /404.shtml
Options All -Indexes
<Files 403.shtml>
order allow,deny
allow from all
</Files>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?mydomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?seconddomain.com [NC]
RewriteRule .(zip)$ - [F,NC]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]
I've got some stuff for Wordpress in there, and then it goes straight on to the hotlinking. I've got my domain listed as well as "seconddomain.com", so that they can link to my ZIP files directly. I then have a redirect in there, since my Wordpress installation is on www.mydomain.com, to redirect to that if they don't happen to use the www.
Now, for the problem. That seconddomain.com is still unable to link to my ZIP files, regardless of the exception that I made for them.
Any ideas on what I'm missing here? And thank you in advance.
You need to order this stuff like this:
- most specific redirects first (affects low number of pages).
- general non-www to www redirects next.
- rewrites last.
You have also either duplicated the RewriteEngine On directive or you don't have it placed early enough on in the file.
RewriteCond lines are "this AND this" unless you add [OR] to all but the last RewriteCond.
However, you'll have to forgive my ignorance. I'm self-taught when it comes to this stuff, and I learn all this stuff as I go along. So, while I'm finding snippetts of the code I need, I'm not as sure how it all fits together yet. Your statement helped some, and thank you.
So, basically I change it to this:
ErrorDocument 404 /404.shtml
Options All -Indexes
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?mydomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?seconddomain.com [NC]
RewriteRule .(zip)$ - [F,NC]
The seconddomain.com is still not able to link to my ZIP file for successful downloads, so I must not have fully understood.
I understand what you meant when you said the non-www to www redirects and then the rewrites last, but I wasn't sure about the "most specific redirects first" part. Is there any way that you could re-order that code there for me to show me an example of what you mean?
Thank you so much!
You need to order this stuff like this:
- most specific redirects first (affects low number of pages).
- general non-www to www redirects next.
- rewrites last.
ErrorDocument 404 /404.shtml
Options All -Indexes
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteBase /
#
# Deny hotlinked requests for .zip files
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example\.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?seconddomain\.com [NC]
RewriteRule \.(zip)$ - [NC,F]
#
# Externally redirect requests for example.com<anything> to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# [ Alternative solution for preceding rule (more thorough) ]
# Externally redirect requests for all non-blank non-canonical
# hostnames to the canonical www.example.com host
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite all requests which do not resolve to a
# physically-existing file or directory to the index.php script
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
[added] Be sure to completely flush (delete) your browser cache after changing any server-side code and between every test using allowed and disallowed linking domains. Otherwise, your browser will show you the previously-cached resources and server responses. [/added]
Jim