I have a favicon.ico on my site.
In the HTML, I link to its location...
<link rel="icon" href="/assets/images/layout/favicon.ico" type="image/x-icon" />
I also have this in my .htaccess.
# Redirect /favicon.ico requests
RewriteCond %{REQUEST_URI} !^assets/images/layout/favicon\.ico [NC]
RewriteCond %{REQUEST_URI} ^favicon\.(gif|ico|png|jpe?g)$ [NC]
RewriteRule ^(.*)$ assets/images/layout/favicon.ico [R=301,L]
...to redirect the /favicon.ico requests to a different location.
For some reason, every time I request favicon.ico in my browser, I get 304 Not Modified response with matching Etags and apparently a blank image, even though /assets/images/layout/favicon.ico does exist.
I get the same issue when trying to access it wil the full path.
What is going on here? What is causing this 304?
First of all I would rather put this rule in .htaccess like this:
RewriteRule ^favicon\.(gif|ico|png|jpe?g)$ /assets/images/layout/favicon.ico [L,NC]
Then if you have this in your web page:
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
/favicon.ico will be internally redirected to /assets/images/layout/favicon.ico
I have tested this in IE, Firefox and Chrome and all 3 show this behavior that for the first time (or after clearing cache) I get 200 for favicon.ico but afterwards all browsers cache this icon file and don't bother to send another request to the server. With this setup I didn't find any 304 happening in my testing.
My access log:
Chrome
127.0.0.1 - - [05/May/2011:23:58:15 -0400] "GET /favicon.ico HTTP/1.1" 200 1150 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.24 (KHTML, like Geck
o) Chrome/11.0.696.60 Safari/534.24"
IE
127.0.0.1 - - [06/May/2011:00:05:18 -0400] "GET /favicon.ico HTTP/1.1" 200 1150 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .
NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
Firefox
127.0.0.1 - - [06/May/2011:00:07:33 -0400] "GET /favicon.ico HTTP/1.1" 200 1150 "-" "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
<IfModule mod_rewrite.c>
RewriteRule ^favicon\.ico$ _/img/ico/favicon.ico [L]
RewriteRule ^apple-touch-icon\.png$ _/img/ico/apple-touch-icon.png [L]
RewriteRule ^apple-touch-icon-precomposed\.png$ _/img/ico/apple-touch-icon-precomposed.png [L]
RewriteRule ^apple-touch-icon-57x57-precomposed\.png$ _/img/ico/apple-touch-icon-57x57-precomposed.png [L]
RewriteRule ^apple-touch-icon-72x72-precomposed\.png$ _/img/ico/apple-touch-icon-72x72-precomposed.png [L]
RewriteRule ^apple-touch-icon-144x144-precomposed\.png$ _/img/ico/apple-touch-icon-144x144-precomposed.png [L]
RewriteRule ^apple-touch-icon-114x114-precomposed\.png$ _/img/ico/apple-touch-icon-114x114-precomposed.png [L]
Related
I have a site with the following structure:
/
|
folder1
|
index.php
index.html
Default is to open index.php but if user is not logged in I do:
header('Location: '.$domain.'/folder1/index.html');
exit;
This works fine for any folder but for folder1 I have also an .htaccess (locate at the root of the site) to handle some logics on index.php.
The .htaccess is the following:
RewriteEngine on
RewriteBase /
RewriteRule \.(php)$ - [L]
RewriteRule ^folder1/([^/]+)/?$ folder1/index.php?source=$1 [L]
I need help to add a rule so that if I request index.html it gets served without inconvenients.
Otherwise now the access.log returns:
10.211.55.2 - - [14/Jan/2021:20:15:50 +0100] "GET /folder1/index.html HTTP/1.1" 302 589 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"
and keeps an infinite loop that ends with firefox saying "this site is not redirecting properly".
For any other folder where the .htaccess is not applied access.log shows the correct behaviour:
10.211.55.2 - - [14/Jan/2021:21:30:52 +0100] "GET /folder2/ HTTP/1.1" 302 4230 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"
and the browser correctly displays the index.html
How do I fix the .htaccess to handle the redirect from index.php to index.html?
RewriteRule \.(php)$ - [L]
You could just add another exception, just as you have done for .php files. For example, after the rule above, but before your rewrite to index.php:
RewriteRule ^folder1/index\.html$ - [L]
Any request for /folder1/index.html goes no further, so is not rewritten to index.php by the directive that follows (so no redirect occurs).
I have a problem with Pinterest : a pin to a page of my website has pushed away my own page from Google results.
I would like to block any crawl or new pin of this specific page from Pinterest
Pinterest User Agent is :
Pinterest/0.2 (+https://www.pinterest.com/bot.html)
Mozilla/5.0 (compatible ; Pinterestbot/1.0 ; +https://www.pinterest.com/bot.html)
Mozilla/5.0 (Linux ; Android 6.0.1 ; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Pinterestbot/1.0; +https://www.pinterest.com/bot.html)
Pinterest Bot IP range is :
54.236.1.XXX.
For the example, the page I want to block contains "substring" in it's URL
Here is my code in .htaccess and obviously it's not working :
RewriteEngine On
RewriteCond %{REQUEST_URI} substring [NC]
RewriteCond %{HTTP_USER_AGENT} pinterest [NC,OR]
RewriteCond %{HTTP_REFERER} ^(www\.)?pinterest\. [NC,OR]
RewriteCond %{REMOTE_ADDR} ^54\.236\.1\.
RewriteRule .* - [F]
Thank you for your help !
I'm trying to block 1 specific user that is constantly scraping my site by hand. He uses a VPN, so IP blocking doesn't work. I can't seem to get him blocked via my HTaccess file. I'm using the following code which is the escaped version of this user agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36 OPR/65.0.3467.48
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
SetEnvIfNoCase User-Agent "Chrome version 0\.0 running on Win10 Mozilla\/5\.0 \(Windows NT 10\.0; Win64; x64\) AppleWebKit\/537\.36 \(KHTML, like Gecko\) Chrome\/78\.0\.3904\.97 Safari\/537\.36 OPR\/65\.0\.3467\.48" bad_bot
Deny from env=bad_bot
</IfModule>
Does this make any sense? I don't want to block too many other users with this piece of code, but I'm afraid that user agent is quite common.
Thanks in advance!
Ps. This goes way beyond my knowledge, but feel free to drop in any technical solutions or language and I'll figure it out with a dev friend.
I had many URLs with square brackets. Then I changed these URLs and removed all square brackets from them, but I still get soft 404 errors, because old URLs are indexed in the web. The URLs are vary, I can redirect each URLs manually, but It will be better if I'll use some universal rule in .htaccess, which removes all square brackets from the URLs.
http://www.example.com/page-[first]
http://www.example.com/page-[second]
etc.. will replaced with:
http://www.example.com/page-first
http://www.example.com/page-second
Can I do it with .htaccess?
Thank you
Try this:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\[(.*)$ $1$2 [N,R=301]
RewriteRule ^(.*)\](.*)$ $1$2 [N,R=301]
If your .htacess is in a sub folder, change RewriteBase / with:
RewriteBase /sub-folder-name
Here's my access_log - which shows the redirections:
::1 - - [04/Jun/2016:12:29:23 +0800] "GET /test/hello-[world].html HTTP/1.1" 301 246
::1 - - [04/Jun/2016:12:29:23 +0800] "GET /test/hello-world.html HTTP/1.1" 200 3
::1 - - [04/Jun/2016:12:37:45 +0800] "GET /test/hello-%5bworld%5d.html HTTP/1.1" 301 246
::1 - - [04/Jun/2016:12:37:45 +0800] "GET /test/hello-world.html HTTP/1.1" 304 -
You can do this redirection using a single rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} /page-(?:%5B|\[)(.*?)(?:%5D|\]) [NC]
RewriteRule ^ /%1 [R,L]
This works to redirect IE to a new page, but I only want to redirect IE11 to a new page. Any ideas?
<!--[if IE]>
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com">
<![endif]-->
This is the IE 11 user agent --> Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko
in htaccess in the document root :
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} IE11 [NC]
RewriteRule ^ http://google.com/ [L,R]