Trailing slashes |
[eluser]Riley123[/eluser]
I'm having problems with trailing slashes on my urls. I've tried the htaccess file in the guide and other suggestions but so far nothing works. my url is http://localhost/ci_matrix/services but if i add a trailing slash http://localhost/ci_matrix/services/ I get the same page with all broken images, css etc http://localhost/ci_matrix/index.php is the main file services is a controller to the services page. this is the htaccess file i am using <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /ci_matrix/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond $1 !^(index\.php|images|robots\.txt|includes|css) RewriteRule ^(.*)/?$ index.php/$1 [L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule> my config settings are: $config['base_url'] = "http://localhost/ci_matrix/"; $config['index_page'] = ""; $config['uri_protocol'] = "REQUEST_URI"; $config['url_suffix'] = ""; this is frustrating cause this is just a test site i am working on to try out codeigniter and if i can't solve this I will be forced to look at another framework. thanks in advance.
[eluser]Colin Williams[/eluser]
Learn how to properly use relative vs absolute paths. This has nothing to do with CodeIgniter. It's web design 101
[eluser]Daniel Moore[/eluser]
Colin is correct. This has nothing to do with the framework. You can't use absolute paths. You shouldn't even be putting the paths into your HTML or PHP directly at all. Use the helpers that come with CodeIgniter. You need to correctly use the HTML Helpers and URL Helpers built into CodeIgniter and not type in absolute paths to load your CSS and images. Open up your CodeIgniter documentation and take a look at the HTML Helper and URL Helper. They are your friends. You might especially check out the link_tag() and img() for your particular problems.
[eluser]Riley123[/eluser]
Colin assumed I'm using absolute paths. I'm not. They are all relative. This has something to do with the htaccess file removing the index.php or codeiginiter's routing is just messing up on CI websites that are placed in subfolders. I've found problems on the forum http://ellislab.com/forums/viewthread/114151/ (seems to be opposite of my problem) http://ellislab.com/forums/viewthread/111837/ (same problem but fix doesn't work for me).
[eluser]Daniel Moore[/eluser]
The second link you posted, which you stated is the same problem as yours but does not fix it, is understandable why it doesn't fix it. The first rewrite has the L modifier: Code: RewriteRule ^(.+[^/])$ $1/ [R,L] The L modifier tells Apache that this is the LAST rewrite rule to handle, and not to handle any further rewrites. That should be removed here, so that the next conditions and rewrite can be properly handled. All this one does is check to see if someone tried to access an invalid file or directory (hence a CodeIgniter URL), then checks to see if it is missing the trailing slash, then adds the trailing slash if missing. It forces the trailing slash for all CodeIgniter URLS. It's the second one you're interested in here: Code: RewriteRule ^(.*)$ /index.php/$1/ [L] Notice what this one does is handles the rewrite WITH the trailing slash at the end of the URL. This is what you need, however, I would recommend changing the [L] to [L,NC,QSA] and see if that clears up your problem. In case that doesn't work, then please post an example of your view showing how you handle the link to your CSS and a link to an image that does not work. There is really no reason the CSS and images should be a problem if you are using this .htaccess, and, if it is, then it may be a problem with the way you are linking. Please provide us with an example so we can help further.
[eluser]Riley123[/eluser]
ok set my htaccess to this: RewriteEngine on # Fix the trailing slash problem RewriteBase /ci_matrix/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+[^/])$ $1/ [R] # Redirect all calls to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(images|robots\.txt|includes|css) RewriteRule ^(.*)$ index.php/$1/ [L,NC,QSA] the problem is still there. If I call http://localhost/ci_matrix/services/ it will show no images or css (relative paths) The images are now being set to http://localhost/ci_matrix/services/incl...eature.jpg when they should be in the http://localhost/ci_matrix/includes/MEDI...eature.jpg path. The controller call services should be ignored. calling http://localhost/ci_matrix/services with no slash displays correctly. My views are not in subdirectories it's all really a simple site.
[eluser]Daniel Moore[/eluser]
You haven't really given me what I've asked for here for me to be able to assist you. I need to see how you link your CSS in your view. Can you please provide that line of code? Also give the location relative to your index.php of where your style sheet resides. Also, give an example from your CSS file of where you have assigned an URL to an image.
[eluser]Riley123[/eluser]
ok in my view I am linking to my css like this: <link rel="stylesheet" type="text/css" media="all" href="includes/_CSS/theme1/style.css"/> and images: <img src="includes/MEDIA/IMAGES/air_flash_developers.jpg" width="240" height="50" /> includes folder is in the same directory as my index.php absolute paths would be http://localhost/ci_matrix/index.php http://localhost/ci_matrix/includes/css/.../style.css http://localhost/ci_matrix/includes/medi...eature.jpg
[eluser]Riley123[/eluser]
ok i just installed Bamboo invoice and looked at their code since it works on my server with trailing slashes. They are using <?php echo base_url()?> before all links. I guess I will have to update all the links in my old site. Thanks everyone for the help.
[eluser]Daniel Moore[/eluser]
Yes, that is why I was telling you to look at things like link_tag() and img(), etc. in a previous post. They handle that base_url() part for you. For example, straight from one of the CI Manual pages I pointed you to earlier, Code: $link = array( Notice how the path in the array definition is 'css/printer.css' yet it is translated to a full site url path? This is how base_url() will help you as well. |
Welcome Guest, Not a member yet? Register Sign In |