I made a website, I threw it on hosting and I have a problem. Well, on the hosting, photos and .css files work normally and load normally, but not on localhost.
I noticed that the problem is the path to which he gives to photos or .css files
For example that looks for some image:
<img data-src="{{ base_url() }}/public/images/background-pattern4.png" class="background-pattern-4" uk-img>
And this way works on hosting, but it does not work on localhost. However, when I remove 'public' from the path, it works the other way around. At localhost works and not on hosting.
I have 2 .htaccess files, first on root folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>
And second.. in public folder:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
What can I change to make the tracks work in both sides?
Are you using Laravel framework? the syntax looks like a blade template syntax. If yes then you might want to use the asset helper function like so:
<img data-src="{{ asset('images/background-pattern4.png') }}" class="background-pattern-4" uk-img>
Here's the documentation link
Related
I'm moving a blog from one site to another and repurposing the original site. I want to maintain all existing links that point to the site and hopefully maintain SEO page ranking.
Old URL: http://www.companyabc.com/2010/04/test.html
New URL: http://blog.companyabc.com/2010/04/test.html
The way I'd like to do it is to use a custom 404 error page on www.companyabc.com like this:
<html><meta http-equiv="REFRESH" content="0;url=http://blog.companyabc.com/%1"></html>
where %1 is the original URI (/2010/04/test.html), but I don't know if that's possible.
Another option is to use an .htaccess file that redirects if the URL is not found, but I haven't gotten that to work either. I'm sure I'm doing something wrong in the rewrite condition:
RewriteEngine On
RewriteCond %{REQUEST_URI} !-l
RewriteRule ^(.*)\.html$ https://blog.companyabc.com/$1.html [R=301,L]
Any suggestions? Thanks for the help.
I got it working using the following .htaccess configuration:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://blog.companyabc.com/$1 [R=301,L]
I never tried the REQUEST_FILENAME value because I mistakenly thought it only applied to files that can be downloaded from the website. I didn't realize it also applies to the .html files in the blog.
With this solution all URLs that don't exist at www.companyabc.com will be redirected to blog.companyabc.com instead of showing a 404 error page, which is what I'm looking for.
I'm trying to get rid of the .html in the url of pages, and I found that code in the .htaccess file is the only way doing so and I've tried nearly every method and code online but it just wouldn't work.
Made an .htaccess file and put it in the public_html file. The general code I'm using is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
But I've tried many many many other variations of the code so I think the issue isn't with the code but the way the file is getting loaded in to the website?
And yes, all my hrefs are shortened without the .html: ex/ <li>Contact</li>
The main error is in that I always get a 404 error - not found for when I try to go to a page, ex/ website.com/contact. But website.com/contact.html works fine or cannot get / error
I've tried this on both my hosted website and testing through vscode live server and I feel like it's an issue not with the .htaccess file somehow? Since this solution works for nearly everyone but me.
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
is what worked for me, from plothost , you seem to be missing a line.
I have a domain for example https://test.com this domain contain a full project in https://test.com/system.
Problem:
Whenever I write <link ref="stylesheets" href="/style/main.css"> it search in the domain root not in the system directory which the project in.
What I have tried to do:
I have tried to edit all my path to be equal to href="style/main.css" instead of href="/style/main.css".
This solution works but I won't do this every time I go in production mode.
What I am trying to do:
I know there is a solution using .htaccess but I don't know how to write it..
Try
<link ref="stylesheets" href="./system/style/main.css">
or
<link ref="stylesheets" href="../system/style/main.css">.
If it still won't work, use three dots.
<link ref="stylesheets" href=".../system/style/main.css">.
It has worked for me.
To set a subdirectory as root with .htaccess
It will depend, with some hosting services you only need to add this line:
RewriteBase /system
If that doesn't works for you, try this:
RewriteEngine On
# Map http://www.example.com to /system.
RewriteRule ^$ /system/ [L]
# Map http://www.example.com/x to /system/x unless there is a x in the web root.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/system/
RewriteRule ^(.*)$ /system/$1
# Add trailing slash to directories within system
# This does not expose the internal URL.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^system/(.*[^/])$ http://www.example.com/$1/ [R=301]
I am currently trying to using .htaccess to do the following:
When b/ is found in the url, it redirects to browse.html. My .htaccess file looks like:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^b/(.*)$ browse.html [NC,L]
I am using Apache version 2.2.31 and here is what my directory looks like:
Root
Root/browse.html
Root/[css]
Root/css/browse.css
Root/[js]
Root/js/browse.js
When I do this, it brings me to browse.html but nothing loads correctly. Every file in the css and js directories become browse.html. Is there something extra I need to add to this?
Here is what the dev tools directory looks like with the .htacess
localhost
b/?page=1 (browse.html file. Name comes from query string)
b/[css]
b/css/browse.css (blank file)
b/[js]
b/js/browse.js (browse.html instead of browse.js)
I have tried putting RewriteBase / in between but that does nothing to the problem.
Your rewrite rule is fine. Problem is happening due to your use of relatives paths for css/js/images. While resolving relative paths browser appends it to current page's path.
You can add this rule above your existing rule::
RewriteEngine On
# fix css/js paths
RewriteRule ^b/.*((?:js|css)/.+)$ /$1 [NC,R=301,L]
RewriteRule ^b/(.*)$ browse.html [NC,L]
Make sure to ignore requests if files/folders exists:
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^b/(.*)$ browse.html [NC,L]
Using CodeIgnitor to manange this site I have configured the css in the following location:
{link rel="stylesheet" type="text/css" href="<? echo base_url();?>application/assets/css/public.css" />
Firebug shows me that the link points exactly where it should, unfortunately,
The problem is I keep getting 403 errors when it tries to load it.
my .htaccess file looks like this, and by the way, I don't really know what I'm looking at here:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|application/assets/js|application/assets/css|application/assets/images)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
RewriteCond $1 ^(images|js|css)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./public/$1 [L,QSA]
How do I get this CSS to load?
Additional Info:
In that the assets folder there is also a js folder and an images folder and the favicon is NOT being pulled from that images folder either.
It sounds like the configuration on that folder and/or the server are refusing you access to read the file.
http://en.wikipedia.org/wiki/HTTP_403
Try navigating directly to the css file and you can easily confirm that you are getting a 403 error, if so it is to do with permissions.
Try accessing your development site remotely rather than from the same machine and you may see the same error there.