Remove index.php from URL |
Following the instructions at http://www.codeigniter.com/userguide3/general/urls.html, I can get the index.php removed from the URL of regular links, e.g., http://www.foo.com/index.php, using this .htaccess entry:
Code: RewriteEngine On Now, there is a scenario where there is a redirect inside of a controller that should go to something like http://www.foo.com/bar/foo However, the redirect goes to http://www.foo.com/index.php/bar/foo instead. Directly typing http://www.foo.com/bar/foo works fine. It's just the redirect that adds the index.php for some reason. The redirect is very simple: PHP Code: public function index() How do I can get rid of the index.php in the URL of a redirect? Thanks in advance!
(04-30-2015, 12:01 AM)eci35 Wrote: Following the instructions at http://www.codeigniter.com/userguide3/general/urls.html, I can get the index.php removed from the URL of regular links, e.g., http://www.foo.com/index.php, using this .htaccess entry: Have you removed the $config['index_page'] = 'index.php'; to $config['index_page'] = ''; Also I have a whole list of different htaccess you could try here Codeigniter Htaccess Github
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!
(04-30-2015, 12:10 AM)riwakawd Wrote: Have you removed the $config['index_page'] = 'index.php'; to $config['index_page'] = ''; Setting $config['index_page'] in the config.php file worked. Thank you! The list of different htaccess will definitely come in handy. Thank you for the reference.
I managed to remove index.php with .htaccess, now I cannot get to subfolders like css, js and so on. Any suggestions ?
![]()
How are you loading your css/js? Show the code. Also, where are css/js subfolders located? They should be in the site root, not in /application or /system dirs.
04-30-2015, 01:01 PM
(This post was last modified: 04-30-2015, 01:03 PM by ivantcholakov. Edit Reason: Address )
@eci35
Before: http://my-site.com/index.php/ Now: http://my-site.com/ The browser interprets the additional segment index.php as an additional directory level. If in your code you are using relative links to your css, js, images, etc., they would become broken after removing the segment index.php. Use absolute URLs. Code: <img src="<?php echo base_url('assets/img/my-image.png'); ?>" /> If you insist on relative links, there is another trick by using the tag <base href="<?php echo base_url(); ?>" /> within the document head, but I don't use it, it brings side-effects on anchor links.
@ivantcholakov
Thank you for the clarification. So far, I've been using absolute URL's to be safe. And I saw echo base_url(); but did not know that it brings side-effects. What sort of side effects are you referring to? Performance-related?
04-30-2015, 01:54 PM
(This post was last modified: 04-30-2015, 02:18 PM by ivantcholakov. Edit Reason: Another link ) Code: <a href="#section-1">Section 1</a> Also, often you can see links like Code: <a id="action" href="#">Action</a> The base tag will modify behavior of anchor links like these and additional manual corrections would be needed. http://www.ninthavenue.com.au/blog/using...th-anchors Edit: http://webdesign.tutsplus.com/articles/q...-cms-21399 - a better explanation. Again, for a web application I would not recommend this way. Use absolute URLs for assets. |
Welcome Guest, Not a member yet? Register Sign In |