Forum Moderators: phranque
RewriteEngine on
#
# This rule needed if you use a custom 403 error page to prevent looping on Forbidden responses
RewriteRule ^path-to-my-custom-error-page\.html$ - [L]
#
# Return 403-Forbidden to unwelcome/malicious user-agents
RewriteCond %{HTTP_USER_AGENT} ^Morfeus [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Toata\ Dragostea [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^ZmEu [NC]
RewriteRule ^ - [F]
#
# Return 403-Forbidden response for hotlinked image requests
# (See alternate internal-rewrite rule at the bottom)
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?websiteA.com [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?websiteB.com [NC]
RewriteRule \.(jpe?g|gif|bmp|png|ico)$ - [F]
#
# (Example only) Redirect specific old page URL to new page URL
RewriteRule ^old.html$ http://www.websiteA.com/new.html [R=301,L]
#
# Externally redirect old mod_userdir-format requests to canonical hostname
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /~adminxx/[^\ ]*\ HTTPS/
RewriteCond %{HTTP_HOST} ^(www\.)?our-big-hosting-company\.com [NC]
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://www.websiteA.com/$1 [R=301,L]
#
# Externally redirect certain non-canonical hostnames to canonical hostname, preserving http/https protocol
# FQDN-format www.websiteA.com or with appended port number
RewriteCond %{HTTP_HOST} ^www\.websiteA\.com(\.|\.?:[0-9]+)$ [NC,OR]
# www- or non-www websiteB.com
RewriteCond %{HTTP_HOST} ^(www\.)?websiteB\.com [NC,OR]
# www- or non-www our-big-hosting-company.com hostname
RewriteCond %{HTTP_HOST} ^(www\.)?our-big-hosting-company\.com [NC]
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://www.websiteA.com/$1 [R=301,L]
#
# If you like informing people who are doing things that they shouldn't be
# doing about your Web site's protections (not really a good idea), then
# use this rule instead of the Forbid-hotlinking rule above:
# Return alternate image for hotlinked image requests
RewriteCond %{REQUEST_URI} !^/images/hotlinked\.gif$
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?websiteA.com [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?websiteB.com [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?our-big-hosting-company\.com [NC]
RewriteRule \.(jpe?g|gif|bmp|png|ico)$ images/hotlinked.gif [NC,L]
[edited by: jdMorgan at 6:03 pm (utc) on Aug 12, 2010]
# Externally redirect old IP-address/mywebsite.com/ -format requests to canonical hostname
RewriteCond %{HTTP_HOST} ^[0-9]+(\.[0-9]+){3}
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^mywebsite\.com/(.*)$ http%2://www.websiteA.com/$1 [R=301,L]
RewriteCond %{HTTP_REFERER} 444\.44
RewriteRule .* [F]
RewriteRule ^(.*)444\.44(.*) - [F]