Forum Moderators: phranque
[edited by: Ocean10000 at 6:06 pm (utc) on Nov 20, 2014]
[edit reason] Examplified [/edit]
The order is right, but the labels are a little inaccurate. The pattern for the index redirect has no closing anchor, so this rule includes requests for "index.html/" alongside the ordinary "index.html". Rule 4c then scoops up any remaining requests for "something-else.html/". Or, technically, .html with any kind of appended garbage; it just happens to be / here.
#Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
#
AddType text/x-component .htc
#Do not allow access to the directories -For security reasons, Option followsymlinks cannot be overridden.
Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
#1 # block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_REFERER} buttons\-for\-website\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
#2 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example\.net/
RewriteRule .*\.(jpe?g|gif|png|bmp)$ - [F]
#3 redirects from file that changed name
#3a
RewriteRule ^Pinto/oldindex\.html http://example.net/Pinto/oldindex.php [R=301,L]
# 3b
RewriteRule ^Asia/Indonesia/bali\.html http://example.net/Asia/Indonesia/bali.php [R=301,L]
# 3c
RewriteRule ^Asia/Indonesia/indonesia\.html http://example.net/Asia/Indonesia/indonesia.php [R=301,L]
# 3d
RewriteRule ^Americas/DomRepublic/DomRepublic\.html http://example.net/Americas/DomRepublic/StoDomingo.php [R=301,L]
#4a index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
#4b domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
#5
# BEGIN EXPIRES
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType css/js "access plus 1 week"
ExpiresByType text/plain "access plus 1 week"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 2 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
#Set charset
<filesMatch "\.(htm|html|css|js|php)$">
AddDefaultCharset UTF-8
</filesMatch>
leave a line between rules
a) Webmasters Tools keeps throwing up an error regarding http://example.net/
it is the final slash that is apparently not covered
#2 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example\.net/
RewriteRule .*\.(jpe?g|gif|png|bmp)$ - [F]
#2 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example\.net/
RewriteRule .*\.(jpe?g|gif|png|bmp)$ - [F]
to accept example.net/ and open the page e[x]ample.net
Webmasters Tools ... continually not being able to find http://example.net/
I was referring to
#1 # block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_REFERER} buttons\-for\-website\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
buttons\-for\-website\.com RewriteRule (^|/|\.html)$ - [F] #1 # block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [OR]
RewriteCond %{HTTP_REFERER} buttons\-for\-website\.com [OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule (^|/|\.html)$ - [F]
At the beginning you write "Where you say .* in the rule you can instead say .? "
but then at the end you suggest "RewriteRule (^|/|\.html)$ - [F] "
But how does the system know if semalt is .com or .net or .co.uk?
I've just realized that what Google was moaning about was http://example.net/index.html/
I guess I can ignore this as I cannot see any visitor getting to my site typing that url
RewriteCond %{REQUEST_URI} ^([^.]+\.html)
RewriteRule \.html. http://www.example.com/%1 [R=301,L] #1 # block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} (semalt|buttons-for-website) [OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
RewriteCond %{REQUEST_URI} ^([^.]+\.html)
RewriteRule \.html. http://www.example.com/%1 [R=301,L]
#4a index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
#4b domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
#4a index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
but in which category shall I add
first can you confirm that the #1 is correct?
Your comment about $ left me confused. Are you saying I should add it?
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L] RewriteRule ^(.*)index\.html http://example.net/$1 [R=301,L] RewriteCond %{HTTP_REFERER} (semalt|buttons-for-website) [OR]
#1 # block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_REFERER} buttons\-for\-website\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
#4a index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html
RewriteRule ^(.*)index\.html http://example.net/$1 [R=301,L]
#4b domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
Example Domain
This domain is established to be used for illustrative examples in documents. You may use this domain in examples without prior coordination or asking for permission.
More information...
[edited by: Ocean10000 at 7:02 pm (utc) on Nov 24, 2014]
[edit reason] examplified [/edit]
the url that includes index with or without slash jumps to a real example.net
http:// is automatically converted into a clickable link. This makes posted rules unreadable-- a serious problem in the Apache subforum. [edited by: Ocean10000 at 7:23 pm (utc) on Nov 24, 2014]
[edit reason] examplified [/edit]
I am starting to think that this is something that disappears once you clear the cache.
But could you try
#4a index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html
RewriteRule ^(.*)index\.html http://example.net/$1 [R=301,L]
#4b domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
[edited by: qimqim at 6:53 am (utc) on Nov 24, 2014]