I'm having problems getting a favicon to work for my website.
I've got two domains pointing to one hosting account, one points to the root and the other (the one I'm talking about here) to a folder on the root.
They both have .htaccess files to deal with 404 requests, shortening the url and redirecting favicon requests. I'm using .htaccess files because it's relatively easy to do for me (I don't have the time to be changing it to something else).
But this website, the one in a folder on the root, won't show the favicon. Everything is in place as it should be. But it just doesn't show a favicon when I go on to it.
Here's the bit of html:
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
Here is the .htaccess file:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{HTTP_HOST} !^getfilm.co.uk$ [NC]
RewriteRule ^(.*)$ http://getfilm.co.uk/$1 [L,R=301]
<ifmodule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC]
RewriteCond %{REQUEST_URI} favicon\.ico [NC]
RewriteRule (.*) http://getfilm.co.uk/favicon.ico [R=301,L]
</ifmodule>
if you write href="favicon.ico" it means, your icon is located beside your page. if your page is in other folder you need to address the folder/icon.ico
Related
I am trying to redirect the main page to a blog. I am using the htcaccess code like this
Redirect / http://coolefitness.com/blog
The result is http://coolefitness.com/blogblogbloglblogblog
no idea why it is repeating the blog. I haven't told it to do that. I don't even know how I would make that loop happen.
Here is my full htcaccess
DirectoryIndex index.php
Redirect /index.html http://coolefitness.com/index.php
Redirect /members.html http://coolefitness.com/members.php
Redirect /what-is-coolefitness.html http://coolefitness.com/what-is-coolefitness.php
Redirect /instructors.html http://coolefitness.com/instructors.php
RewriteEngine On
#Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
RewriteRule ^([^/]+)/$ http:/coolefitness.com/blog/$1 [R=301,L]
Redirect / http://coolefitness.com/blog
ErrorDocument 403 /404.php
ErrorDocument 404 /404.php
ErrorDocument 500 /404.php
FallbackResource payment/app.php
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
I have tried doing a rewrite, but that isn't working. I have removed it and the issue still happens.
I'm having some trouble while using RewriteRule on my local and remote servers.
Here's the situation I'm in right now:
localhost/puntvallesgit/index.php?seccion=nosaltres
this is the actual URL
I want it to be renamed to:
localhost/puntvallesgit/nosaltres
and
localhost/puntvallesgit/nosaltres/
Both urls work, meaning, it does not give me a 404 or something like that, but, with the second one (localhost/puntvallesgit/nosaltres/) there's no CSS nor JS loading correctly.
Looking the html code, I can see that while using the rule, the url path for JS and CSS gets changed to:
localhost/puntvallesgit/nosaltres/css/styles.css
yet the code itself has this:
<link href="./css/styles.css" rel="stylesheet">
I understand that sine I'm rewritting the url, to /nosaltres ... the html code adapts to that new folder structure, but that is not the expected behaviour.
Also, while using the url without the final slash (localhost/puntvallesgit/nosaltres) it works great (under localhost).
I could use absolute paths, yet, that is not the most ideal thing to do, since then paths would change from my localhost to my remote server
Here's the htaccess rewrite i'm using:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^/]*)$ index.php?seccion=$1 [NC]
RewriteRule ^([^/]*)/$ index.php?seccion=$1 [NC]
</IfModule>
Some advice please?
Thanks in advance
You can add the base tag between the <head> </head> section of your site. Then your asset folders will read from the root.
<base href="/">
Also rewritecond only works for the first rewrite following it. You can condense your rule this way.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^/]*)/?$ index.php?seccion=$1 [NC,L]
</IfModule>
This is not htaccess related (although your rewrite rules are not optimal), but rather a problem in the way you load your stylesheet.
When browsing to http://localhost/puntvallesgit/nosaltres/, the browser will try to load your stylesheet from ./css/styles.css which translates to http://localhost/puntvallesgit/nosaltres/css/styles.css, while your stylesheet is probably at http://localhost/puntvallesgit/css/styles.css.
You should use /puntvallesgit/css/styles.css as the source of your stylesheet instead.
I'm making a .htaccess for my web page, here's the code:
Options -Indexes
RewriteEngine On
RewriteRule ^([A-Za-z]+)/([0-9]+)/$ files.php?row=$1&column=$2
RewriteRule ^([A-Za-z]+)/?$ $1/1/
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mywebpage\.at [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://.*$
RewriteRule \.(jpe?g|gif|bmp|png)$ /imgs/hotlinks.png [L]
RewriteCond %(REQUEST_URI) ^imgs/$ [NC]
RewriteRule / - [F]
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
The problem is, my images are not showing up in pages with rewritten URLs. Apparently, their routes are also affected by the rewriting. Simply explained: an image located at www.mywebpage.at/imgs/pic1.jpg loads on www.mywebpage.at/files.php?row=first&column=3, but when I try to enter www.mywebpage.at/first/3/ the browser looks for the image in www.mywebpage.at/first/3/imgs/pic1.jpg, and obviously fails to load it.
How can I fix this so that the routes of the images do not change, no matter from where I use them?
You can do:
RewriteCond $1 !^(imgs)
RewriteRule ^([A-Za-z]+)/([0-9]+)/$ files.php?row=$1&column=$2
That will rewrite everything except the imgs folder.
Edit: Apologies, misread question.
Make your image paths absolute. E.g. relative path is:
imgs/image1.jpg
Absolute path is:
/imgs/image1.jpg
The slash at the beginning tells it to go to the very root of the site and then go to imgs, then image1.jpg.
I've just changed permalinks in my wordpress site.
And my old links were like that,
http://www.sitename.com/category/postname.html
Now new links are
http://www.sitename.com/category/postname/
I'm getting 404 error at old links, how can i redirect all .html pages to new non .html pages with .htaccess?
In the htaccess file in your document root, add these before your wordpress rules:
RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/
Of if you need to limit it by hosts, you can use mod_rewrite:
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L]
RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]
In the htaccess file, just put:
Redirect 301 /postname.html http://www.sitename.com/category/postname/
The accepted answer (above) from Jon Lin caused some issues for me.
This is my result, which works well, and is a bit more compact.
It works for both, with and without directories in the path.
Oneliner:
RedirectMatch 301 ^/(.*)\.html$ /$1
Or if you need it limited by host:
RewriteCond %{HTTP_HOST} myDomain.com [NC]
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
Example:
I'm trying to make a simple 2-language site, en and th, I am unfamiliar with .htaccess but found an online tool: http://www.htaccesstools.com/redirection-by-language/
I would like English browsers to go to my root folder's index.html, and Thai browsers to a subfolder.
What I got from the generator is:
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} th [NC]
RewriteRule .* http://www.mysite.com/th/index.html [R,L]
This doesn't work and I get a redirect loop/other error. I've tried changing the url on the last line to be relative, but this doesn't affect it.
Any help?
*to confirm, i have one .htaccess in my root folder only
Try this in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(/th/index.html|.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ [NC]
RewriteCond %{HTTP:Accept-Language} ^th [NC]
RewriteRule .* /th/index.html [R,L,QSA,NE]