Welcome Guest, Not a member yet? Register   Sign In
Newbie question about .htaccess, please help
#1

[eluser]jasonfx[/eluser]
Hi all,

I am new to code igniter and this is my first time posting. I have installed CI on my local machine running WAMP. I've also followed instructions on removing the index.php from the URLs. It works great, but there is a slight problem:

Code:
localhost/ci/ <- works fine
localhost/ci/controller/ <- works fine too
localhost/ci/controller/function/ <- works, but styles and images don't seem to load, therefore the page loads with all html and data, but looks ugly.

This is my .htaccess file:

Code:
RewriteEngine on
RewriteCond $1 !^(index.php|css|js|images|robots.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]


This is my directory structure:

Code:
localhost/ci/ <- installation directory
localhost/ci/.htaccess
localhost/ci/index.php
localhost/ci/system/
localhost/ci/images/
localhost/ci/css/
localhost/ci/js/
#2

[eluser]WanWizard[/eluser]
Which links are generated to css or js files when you request localhost/ci/controller/function/ ? Did you check the HTML?
#3

[eluser]jasonfx[/eluser]
[quote author="WanWizard" date="1288050271"]Which links are generated to css or js files when you request localhost/ci/controller/function/ ? Did you check the HTML?[/quote]

Hi WanWizard,

Thanks for your reply!

The links in the resulting page look like this:
Code:
...
&lt;link href="css/common.css" rel="stylesheet" type="text/css"&gt;
...

Javascript files, and images in the body are also linked the same way. I believe I read somewhere that all links should be relative to the index.php file, is this correct?

Also I hope I placed the images, js, and css folders in the correct location (in the installation root)
#4

[eluser]WanWizard[/eluser]
That explains the problem.

You are using relative links, relative the the current URL. So in case of localhost/ci/controller/function/bla, the link becomes /controller/function/css/common.css.

Always use base_url() in your views to make sure the links are generated correctly.
#5

[eluser]jasonfx[/eluser]
Thanks for your reply.

It seems kind of redundant to have base_url() in every link in the page. Is there possibly a shortcut way of accomplishing this?

Thanks again.
#6

[eluser]WanWizard[/eluser]
Why is it redundant? You still have to prefix your variable part of the URL with the path to your assets.

If they are in the docroot, you can get away with "/css/file.css", with is relative to the root, but it means hardcoding your paths. The main reason for using base_url() is to avoid hardcoding paths.
#7

[eluser]jasonfx[/eluser]
[quote author="WanWizard" date="1288055597"]Why is it redundant? You still have to prefix your variable part of the URL with the path to your assets.

If they are in the docroot, you can get away with "/css/file.css", with is relative to the root, but it means hardcoding your paths. The main reason for using base_url() is to avoid hardcoding paths.[/quote]

That makes a lot of sense.

Thanks a lot for your help!
#8

[eluser]Ciaro[/eluser]
[quote author="jasonfx" date="1288054173"]Thanks for your reply.

It seems kind of redundant to have base_url() in every link in the page. Is there possibly a shortcut way of accomplishing this?

Thanks again.[/quote]

You probably want site_url()
@see http://ellislab.com/codeigniter/user-gui...elper.html




Theme © iAndrew 2016 - Forum software by © MyBB