Forum Moderators: phranque
I tried RewriteRule ^(.*)/+$ $1 [R=301,L] http://example.net/home3/pintotou/public_html/Asia/Indonesia/bali.php
http://example.net/Asia/Indonesia/bali.php
http://example.net/Asia/Indonesia/bali.php
[edited by: phranque at 9:30 am (utc) on Feb 21, 2014]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]
Redirect 301 /Pinto/oldindex.html http://example.net/Pinto/oldindex.php
Redirect 301 /Asia/Indonesia/bali.html http://example.net/Asia/Indonesia/bali.php
Redirect 301 /Asia/Indonesia/indonesia.html http://example.net/Asia/Indonesia/indonesia.php
# 7a
RewriteRule ^Pinto/oldindex\.html http://example.net/Pinto/oldindex.php [R=301,L]
# 7b
RewriteRule ^Asia/Indonesia/bali\.html http://example.net/Asia/Indonesia/bali.php [R=301,L]
# 7c
RewriteRule ^Asia/Indonesia/indonesia\.html http://example.net/Asia/Indonesia/indonesia.php [R=301,L]
# 7b
RewriteRule ^Asia/Indonesia/(bali|indonesia)\.html http://example.net/Asia/Indonesia/$1.php [R=301,L] "Crikey, how did we rack up 30 more posts in one day?"You shouldn' have gone to bed...
Doesn't matter if you originally got the rules from the Pope himself.
# 1 Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
# 2 Do not allow access to the directories
Options -Indexes
# 3
AddType text/x-component .htc
# 4 allow all except those indicated here
<Files *>
order allow,deny
allow from all
</Files>
# block visitors referred from indicated domains
RewriteEngine on
# For security reasons, Option followsymlinks cannot be overridden.
#5 Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
#6 redirect from www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
#7 redirects from file that changed name
# 7a
RewriteRule ^Pinto/oldindex\.html http://example.net/Pinto/oldindex.php [R=301,L]
# 7b
RewriteRule ^Asia/Indonesia/bali\.html http://example.net/Asia/Indonesia/bali.php [R=301,L]
# 7c
RewriteRule ^Asia/Indonesia/indonesia\.html http://example.net/Asia/Indonesia/indonesia.php [R=301,L]
#8 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
Why is that?
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
Options -Indexes +SymLinksIfOwnerMatch Sure, I know where Andorra is.
46.136.11.0/24
46.136.87.0/24
46.136.145.0/24
85.94.160.0/19
91.187.64.0/19
109.111.96.0/19
185.4.52.0/22
194.158.64.0/19
Physically it's in Basque-land. But that's another matter.
# block visitors referred from indicated domains
RewriteEngine on
# For security reasons, Option followsymlinks cannot be overridden.
#5 Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
I end up with a section that does not seem to make much sense:
# For security reasons, Option followsymlinks cannot be overridden.
# 1 Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
# 2 Do not allow access to the directories - For security reasons, Option followsymlinks cannot be overridden
Options -Indexes +SymLinksIfOwnerMatch
# 3
AddType text/x-component .htc
# 4 allow all except those indicated here
<Files *>
order allow,deny
allow from all
</Files>
RewriteEngine on
#5 block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
When I moved here, from Portugal, the removals firm asked me if the lorry (truck) had to get on a ferry-boat...
Throw out all those
#4 comment
Then number only the RewriteRules.
In the cheesy 18th-century novel The Victim of Magical Delusion there are at least two major scenes where a character is shipwrecked ... en route from Spain to Portugal. Never let geography get in the way of a good plot device.
#Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
#Do not allow access to the directories -For security reasons, Option followsymlinks cannot be overridden.
Options -Indexes +SymLinksIfOwnerMatch
#
AddType text/x-component .htc
RewriteEngine on
#1 # block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
#2 redirect from www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
#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]
#4 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
#4 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]
/.*$ $ ^http://example\.net($|/) (www\.)?example\.net #bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [L,NC]
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Are you saying it should be [AND] instead?
RewriteCond %{HTTP_HOST} !^(www\.example\.net)?$ ^http://www\.example\.net/ One of my pages lost ALL its images. I didn't check the others.
So, I took the #4 code out altogether and the pics came back.
Is it because of the missing "!" ?
Are you saying that the code is useless then? I understood that main reason was to stop thieves from stealing my pics
#Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
#Do not allow access to the directories -For security reasons, Option followsymlinks cannot be overridden.
Options -Indexes +SymLinksIfOwnerMatch
#
AddType text/x-component .htc
RewriteEngine on
#1 # block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]
#2 redirect from www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
#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]
#4 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://www\.example\.net/
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [L,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html
RewriteRule index\.html http://www.example.com/%1 [R=301,L] RewriteCond %{THE_REQUEST} index
RewriteRule ^(([^/]+/)*)index\.html http://www.example.com/$1 [R=301,L] #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_USER_AGENT} libwww-perl
RewriteRule .* – [F]
#2 redirect from www
#redirect from www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301] ]
#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]
#4 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://www\.example\.net/
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [L,NC]
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
^([^/]+/)*index\.html RewriteRule ^(.*)$ http://example.net/$1 [R=301] ]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [L,NC]
[Jj][Pp][Ee]?[Gg]|[Gg][Ii] ... RewriteCond blahblah
RewriteCond blahblah
RewriteRule \.(jpe?g|gif|png)$ /images/hotlink.png [L] And speaking of domain name: All other quoted rules have "example.net" as the preferred form. The hotlinking rule has "www.example.net" -- a form which will never occur, so the rule will only execute when you don't want it to.
#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_USER_AGENT} libwww-perl
RewriteRule .* – [F]
#4 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example\.net/
RewriteRule .*\.(jpe?g|gif|png|bmp)$ - [L,NC]
#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]
#2a index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
#2b domain-name canonicalization redirect
RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
# 5 Set Expires Headers
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 15 Jan 2015 20:00:00 GMT"
</FilesMatch>
# 6 Set the cache-control max-age
# 1 year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=31449600, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
# 4 HOURS
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=14400, must-revalidate"
</FilesMatch>
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]
This looks fine to human eyes, because you look at the pattern and see the "index.html" coming up. But a server only operates in one dimension. So it merrily captures all the way to the end-- and then finds "Oh, oops, I was supposed to leave room for 'index.html'." That's why the pattern has to be expressed as
^([^/]+/)*index\.html
Remember to escape the period! And speaking of periods: If your URL paths don't contain periods, you can replace [^/] everywhere with [^/.] to get the server out of there a few nanoseconds sooner.
Are you saying I need to leave a space between the closing brackets and the beginning of index ?
^([^/]+/)* ^(([^/]+/)*)