Newbie question about .htaccess, please help |
[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 This is my .htaccess file: Code: RewriteEngine on This is my directory structure: Code: localhost/ci/ <- installation directory
[eluser]WanWizard[/eluser]
Which links are generated to css or js files when you request localhost/ci/controller/function/ ? Did you check the HTML?
[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: ... 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)
[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.
[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.
[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.
[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!
[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 |
Welcome Guest, Not a member yet? Register Sign In |