Yet another htaccess issue |
[eluser]kettch[/eluser]
Okay, this is driving me nuts so I have to have another set of eyes take a look. I've got my htaccess working for removing the index.php portion of the URL just fine and have a default controller defined such that if you go to http://www.mywebsite.com/ it loads the default home page, and if you then click on a link that takes you to http://www.mywebsite.com/page/id/123 it also loads that page correctly. However, what it DOESN'T do currently is correctly link the styles, scripts and images directories when the page/id/123 portion is included in the URL rather than the default. Instead of looking for them at http://www.mywebsite.com/images/logo.jpg it looks for http://www.mywebsite.com/page/id/images/logo.jpg which is incorrect. Here is my htaccess: RewriteEngine On RewriteRule ^((images|styles|scripts)/*.*)$ /$1 [L] RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico) RewriteRule ^(.*)$ index.php/$1 [L] Now I'm no rewrite expert (obviously) but I could have sworn the second line would correctly redirect requests for images/logo.jpg to the URL base http://www.mywebsite.com/images/logo.jpg but it doesn't. I'm sure this is something stupidly simple that I'm missing but I'm sick and still trying to get work done and this is driving me nuts. What am I doing wrong?! :question:
[eluser]jedd[/eluser]
In your views, what code are you using to reference the css/images/etc? Oh, welcome to the CI forums, btw. ![]()
[eluser]kettch[/eluser]
To use a javascript example, my src attribute looks like (and works great for the default page load): src="scripts/myscript.js" Thanks for the welcome ![]()
[eluser]jedd[/eluser]
Quote:src="scripts/myscript.js" But what's your actual view code? The whole line, as it were.
[eluser]kettch[/eluser]
I don't understand why the whole line would help rather than just the src attribute value since it's a simple [removed] tag, but the whole line would be (with <> around both ends, otherwise this forum removes the code): Code: script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script which then ends up with the URL: http://www.mywebsite.com/page/id/scripts...3.2.min.js which is incorrect.
[eluser]jedd[/eluser]
It's okay to not understand .. but what you've now shown me identifies the problem, and suggests a solution. The problem is that you're implicitly using relative paths, which nicely explains what you were seeing in your page source (at the browser end). The solution - you need to path your src reference, and there are two obvious ways to do this. Either insert a <?php echo base_url() ?> before the 'scripts/jquer...' bit. Or use the link_tag() function (which is part of CI's [url="http://ellislab.com/codeigniter/user-guide/helpers/html_helper.html"]HTML Helper class[/url] Let me know if you need more detailed information.
[eluser]kettch[/eluser]
Sorry for the confusion, I guess I didn't make it clear that when I said my src attribute was like src="scripts/myscript.js" that meant that was my exact format for the pathing and I was just substituting myscript.js for one of the actual file names...hence my confusion as to why it would matter if the rest of the tag was there or not. ![]() That seems to have done the trick, I completely forgot about the URL helpers...it's been about a month since I last worked on this project so apparently I'm getting old and forgetting things! ![]()
[eluser]Daniel Moore[/eluser]
The line you used: RewriteRule ^((images|styles|scripts)/*.*)$ /$1 [L] will not do what you were thinking. The ^ is the start of line anchor, so it will only redirect when "images/*.*" or "styles/*.*" is at the START of the request. However, when something like http://www.mywebsite.com/page/id/images/logo.jpg is submitted, it won't get redirected because "images/logo.jpg" is not at the start position. This RewriteRule line is entirely unnecessary. You need to follow jedd's advice here: Quote:Either insert a <?php echo base_url() ?> before the ‘scripts/jquer…’ bit. Or use the link_tag() function (which is part of CI’s HTML Helper class
[eluser]pixelazion[/eluser]
Try this ^_^ Code: <IfModule mod_rewrite.c> |
Welcome Guest, Not a member yet? Register Sign In |