I'm testing Klein routing system, https://github.com/chriso/klein.php
it's awesome but i can't get my css ant images to run
This is my directory structure:
index.php
.htaccess
vendor
views
includes
assets
css
images
And here's one of my includes line of code where i try to access my assets/css:
<link href="../assets/css/main.css" rel="stylesheet">
I tried everything. Every possible hint would be great, thanks.
EDIT:
now i think it can be problem in my htaccess. how to make that url won't rewrite if it's css or img?
my .htaccess :
RewriteEngine on
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
Your link is most likely wrong (unless the code you pulled it from is in the include or assets folder). the ".." literally means "up one level". So if you code is in the .htaccess folder (which it usually is I believe) or any folder on that level the correct link would be:
href='../views/assets/css/main.css'
If your code is in css or images (not sure why it would be) the correct link would be:
href='../css/main.css'
Good lcuk!
Related
When I use rewrite rules to clean my URL, I can't access my CSS files. Without the rewrite rules my page works fine, but with the rewrite rules images,CSS and JS documents cannot be linked. What could be the problem?
My .htaccess codes
RewriteEngine On
RewriteRule ^index?$ index.php
RewriteRule ^product_details/([0-9]+) product_details.php?id=$1
Now I don't understand why my edit.php is unable to locate external files even though it loads from the correct path on server-side (mysite.com/). And it does not show the URL in an extra directory (in this case mysite.com/e/).
Mod Rewrite will redirect www.example.com/product_details/123 to product_details.php?id=123 on server-side.
Your browser thinks that /product_details/ points to a directory and resolves relative links accordingly.
The solution is to use absolute paths or add <base href="//www.example.com/"> to your html head element.
I had a look at a few possible duplicates for this question but rewrite rules are fairly specific to projects so I couldn't find a suitable answer.
Crux of issue? Requests for certain files (CSS, JS & images) are being rewritten (I think) by the htaccess file.
I have an htaccess file set up to direct as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]
It takes a URL like localhost/framework/booking/dashboard and rewrites to localhost/framework/index.php?controller=booking&action=dashboard
The relevant file structure inside my local www folder looks something like:
framework
-index.php
-htaccess
-views
-Booking
-dashboard.php
-wuxia-blue.css
The CSS link in dashboard.php is as follows:
<link rel='stylesheet' type='text/css' href="wuxia-blue.css">
The HTTP request being made seems to be:
/framework/booking/wuxia-blue.css
It should be:
/framework/views/booking/wuxia-blue.css
Ideally, I'd like to use something similar to
href="<?php echo(CSS . "wuxia-blue.css"); ?>".
Where CSS is a defined constant in the application and where wuxia-blue.css (and all other css files) are contained in a predefined folder of stylesheets. Obviously this would apply to other assets like .js files and images.
Any ideas?
The htaccess rule is correct - the problem is with your folder structure.
When you create a relative link, it's relative to the current URL as displayed in the address bar - the location of the file you're in isn't relevant.
Your view file is at /framework/views/booking/dashboard.php, but the browser just sees the url /framework/booking/dashboard. That means the browser interprets the location of the resource to be /framework/booking/dashboard/wuxia-blue.css
Personally, I'd recommend just keeping all your css and images outside of the framework in /images and /css. Otherwise, may have to add some code in your framework to serve up image files, since all the image requests will be running through your framework.php file.
I'm having a go at mod_rewrite so that the client can list better urls on Google
So I've created a page (www.cruiseandmaritime.com/cruise_details_by_name.php which is where I send things like
www.cruiseandmaritime.com/cruises/French-Leave
works fine, the page loads with the right data, but there is no stylesheet loaded so it's all just unformatted
Now I'm guessing, that because I have created the imaginary directory 'cruises' its something to with that... ?
Here is my line in the .htaccess file
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
RewriteRule ^cruises/([A-Za-z0-9-]+)?$ cruise_details_by_name.php?id=$1 [NC,L] # Handle requests for all cruises
once again, any help greatly appreciated !
Rich:)
I don't think that's a mod_rewrite problem.
In your html code there's a link to your css file:
<link rel="stylesheet" type="text/css" href="stylesheets/anytime.css" />
Currently the browser is trying to load the file located at http://www.cruiseandmaritime.com/cruises/stylesheets/anytime.css
If you let the file path start with / this should work. That way an absolute uri is used instead of a relative one.
The following issue is driving me crazy, perhaps i am thinking to difficult.
Here is the thing, i developed a small MVC framework that works fine. Atleast without url rewriting.
The problem is that as soon as i use url rewrite, things like the css or images which are included in the templates are directed to the wrong directory.
If i type for example: http://www.domain.com/home then everything is fine and the css file get loaded from the http://www.domain.com/css/ directory.
But when i type: http://www.domain.com/home/ the css file won't be loaded, since its looking for the css files in http://www.domain.com/home/css/ Which is obliviously the wrong directory. It seems it sees home/ as a directory where it looks for the the included files.
If i don't use any url rewriting at all, just by typing: http://www.domain.com/index.php?slugs=home/ then there are no problems at all. So i don't think the problem is caused by my script so thats why i think the problems should be looked for in the .htaccess file.
Here is my htacces file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteRule ^(.*)$ /astrostrategy/index.php?slugs=$1 [L]
Is there a way, that home/test/whatever(The segments) are not seen as a directory?
Hope my post made sense, i often think to complicated :P
Already thanx for any help! :)
Gr,
Hermes.
If Death's answer doesn't work you can always set the base tag to the url to use in relative paths
it seems you're using relative to currect directory path for css. when you use http://www.domain.com/home/ browser takes home as directory and css file will be located in http://www.domain.com/home/css/. my suggestion is use relative to root path. Now you're using something like :
<link rel="StyleSheet" type="text/css" href="css/style.main.css" />
it's better to use absolute path or relative to root path.
<link rel="StyleSheet" type="text/css" href="/css/style.main.css" />
How can I tell CodeIgniter to ignore the /lib/css folder and load my stylesheets instead of trying to load things via my controller?
I'm just going to take it straight from the user guide:
By default, the index.php file will be
included in your URLs:
example.com/index.php/news/article/my_article
You can easily remove this file by
using a .htaccess file with some
simple rules. Here is an example of
such a file, using the "negative"
method in which everything is
redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request
other than those for index.php,
images, and robots.txt is treated as a
request for your index.php file.
With .htaccess: You decide which files and folders can be accessed directly, like css or images.
Without .htaccess: All references to the application are routed through index.php so there is no possibility of conflict
In the example above, two files and one directory (images) are allowed direct access. Any other requests are routed through Codeigniter, so if you HAVE a controller called css and want to access it - you can do so by removing it from this list. If you have a directory named css, you would add it to this list of exceptions and be able to access it, and all files within it, directly.
Another note: do not try to use ../../relative/paths with CI, use full URLs or /absolute/paths. Use the helpers that exist, like base_url(), and link_tag() as seen in Phphelp's example
Your question is not exactly clear. If this is what you want, you can do the following.
echo link_tag('css/mystyles.css');
Gives:
<link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />
In place of mystyles.css, you can give your style sheet.