Welcome Guest, Not a member yet? Register   Sign In
Views - Stylesheets, Javascript, Images
#1

[eluser]_chris[/eluser]
I moved the project I was working on into the code igniter framework.

I have my XHTML in the view, and it loads fine. But the javascript etc does not.
I have moved the javascript, images, and stylesheet folder into the same folder as my index.php which is loaded by the controller.

But the javscript etc isn't being loaded, for example I have:

Quote:<*script src="javascript/jquery-1.4.2.min.js">
(With out the * at the beginning)

Which is in my javascript folder which is in the same folder as my index.php.

Am I meant to place the stylesheets etc somewhere else? Since I have moved my project to code igniter do I have to change the src location of everything ?
#2

[eluser]tonanbarbarian[/eluser]
use absolute links not relative
the problem is that if you are removing the index.php from the url then you might have common urls that look like this
http://example.com/welcome - goes to the default method i.e. index or the controller welcome
http://example.com/welcome/home - goes to the method home in the controller welcome
http://example.com/article/show/3125 - goes to the controller article and calls the show method with a parameter of 3125

Now if you use a relative link such as javascript/jquery.js on each of those pages the browser will resolve these paths to
http://example.com/welcome/javascript/jquery.js
http://example.com/welcome/home/javascript/jquery.js
http://example.com/article/show/3125/jav.../jquery.js

so change your script tag to the absolute url
Code:
<* script src="http://example.com/javascript/jquery.js">
and you will not have any problems no matter where on the site someone is
#3

[eluser]PeterGreffen[/eluser]
If you are using a .htaccess file to (e.g.) get rid of your index.php, be sure to include your css, script and assets folders too... In my example, I have included uploads, captcha, logs, style, images and js...

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|uploads|captcha|logs|style|images|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Did you solve the problem?
P.
#4

[eluser]_chris[/eluser]
I put the .htaccess file in the same folder as my XHTML, images etc.
Now I get a "500 Internal Server Error" when trying to load the website.

I don't actually understand what it is you gave me does exactly.
I don't understand why I should get rid of my index.php ?

And in regards to setting an absolute URL. I have a WAMP setup and I have the project hosted on my local computer. I don't actually have the domain for the project yet, nor do I want to point it to my computer. So if I was to use absolute URL's I have to find a way of getting it to work on my local machine, for that domain to point to the localhost/folder (not sure how to do that.)

I wasn't using a .htaccess file before.


Thanks very much for your help.
#5

[eluser]InsiteFX[/eluser]
The .htaccess file should go into your root folder were your index.php file is.

InsiteFX
#6

[eluser]_chris[/eluser]
I put my .htaccess with my index.php along with the system folder which has all the code igniter folders and files within it.

And I am getting: "500 Internal Server Error".
#7

[eluser]matt.asbury[/eluser]
I have created an assets folder in the same place as the index.php which contains other subfolders including images, js, css. This means that when I amend my .htaccess file to allow access to the folder, I only have to allow this one folder to gain access to all the other folders. I can also keep adding more folders without having to amend the .htaccess file. I have this line in my .htaccess file:
Code:
RewriteCond $1 !^(index\.php|assets|robots\.txt)

Now when I want to access something in one of these folders I reference it absolutely rather than relatively like this:
Code:
&lt;link type="text/css" rel="stylesheet" href="/assets/css/reset.css" /&gt;
&lt;link type="text/css" rel="stylesheet" href="/assets/css/screen.css" /&gt;
<*script type="text/javascript" src="/assets/js/backoffice.js"><*/script>
On a side note, a 500 error would suggest an error with your .htaccess file so take out everything you may have changed and start again. My full .htaccess file (for reference) is:
Code:
Options +FollowSymlinks
RewriteEngine On

RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)/$ /index.php/$1 [L]
Hope that helps.
#8

[eluser]InsiteFX[/eluser]
Take off the first / see below and see if it works.
Code:
&lt;link type="text/css" rel="stylesheet" href="assets/css/reset.css" /&gt;
&lt;link type="text/css" rel="stylesheet" href="assets/css/screen.css" /&gt;
<*script type="text/javascript" src="assets/js/backoffice.js"><*/script>

InsiteFX
#9

[eluser]_chris[/eluser]
It might be outside of the knowledge you guys have.

But maybe I am thinking there is something wrong with my httpd.conf.

As soon as I said one line with "Rewrite" at the beginning I get the 500 server error.

My complete .htaccess is:

Code:
Options +FollowSymlinks
RewriteEngine On
RewriteCond $1 !^(index\.php|images|styles|javascript|robots\.txt)
RewriteRule ^(.*)/$ /index.php/$1 [L]

Which is located my www folder.

I do have "AllowOverride All" but above it I have:

Code:
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

Should AllowsOverride be set to All instead of None?
I don't know that much about the apache config obviously.
#10

[eluser]dudeami0[/eluser]
The base_url() function from the url helper is what I use to make my script locations absolute. Just do:

Code:
<*script src="&lt;?php echo base_url(); ?&gt;location/of/script.js" type="text/javascript"><*/script>

Its what works for me, and doesn't rely on htaccess (Whichs seems to make a 500 Internal Server error everytime I look at it). Hope that helps Smile

Edit: Also with the 500 error your getting, might be rewrite is not enabled in your apache. Check that out first :p




Theme © iAndrew 2016 - Forum software by © MyBB