81 responses to “CodeIgniter htaccess”

  1. igi shellshock

    i follow this tutor, my default controller is ‘dashboard’, it works.people can check here http://jobcareer.polibatam.ac.id but when i tried do like http://jobcareer.polibatam.ac.id/login didn’t work.please help me..thx..

  2. igi shellshock

    thx dimas for reply, this my .htaccess file

    RewriteRule ^(dashboard(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]
    
    RewriteCond %{HTTP_HOST} !^(www|jobcareer) [NC]
    RewriteRule ^(.*)$ http://www.polibatam.ac.id/$1 [R=301,L]
    

    config.php file

    $config['base_url']	= 'http://jobcareer.polibatam.ac.id/';
    $config['index_page'] = '';
    
    		$session->userdata('sesblabla')=="")
    		{
    			redirect('/login/');
    		}else{
    			$data['base'] = $this->config->item('base_url');
    			$this->load->view('dashboard',$data);
    		}
    	}
    		
    	function logout()
    	{
    		$this->session->sess_destroy();
    		redirect('/login/');
    	}
    }
    

    why still access index.php/dashboard/ ? not /dashboard/

  3. T. Brian Jones

    This is a great post. Thanks for taking care of all these details. These are often overlooked and can make a HUGE difference for SEO. I’ve seen sites of mine double their number of indexed pages, almost overnight, after making these improvements. It’s nice to have them done on my new project right from the start.

  4. Johan van de Merwe

    This only works if you have in your config.php file:
    $config['uri_protocol'] = ‘AUTO’;
    Which I hadn’t in first instance (QUERY_STRING).
    Now it works fine.

  5. Harry

    All forms on my site now fail to post with the addition of the htaccess code. Could it be something to do with WAMPserver? I have followed the instructions exactly.

  6. sh

    good art
    @Johan van de Merwe +1
    I had problems with my ajax get requests, had to change them to post and now works fine

  7. Martin Hjort

    You still have to do something in your controllers to prevent access to more than one URL for the same content. I tried using your rewrite_rules, while creating a simple blog controller

    I can access the controllers comments-function through both http://www.fmground.dk/index.php/blog/comments and http://www.fmground.dk/blog/comments

    which leaves an “open SEO wound” :)

  8. allis

    help me pls..
    i have virtual host like this :
    domain => folder in server
    hotels.visitbali.com => www/hotels
    hotels.visitbali.com/kutahotel => www/kutahotel

    if i access hotel.visitbali.com/kutahotel, there no problem.
    but if i access hotel.visitbali.com/kutahotel/customer/booking, no page found.
    customer is controller and booking is function

    can someone help how about .htaccess ??

  9. dude

    after pasting your .htaccess file, my default page goes to domain.ltd. even after i’ve deleted it already. how come?

  10. azwar akbar

    So complete codeigniter htaccess tutorial, awesome…

  11. Antonio

    Hi, Dimas. I’m a noob at this, and I crashed everything.

    I pasted the file u posted into my htaccess file, and now, everytime I try to access my http://localhost/testweb, I get redirected into domain.tld. How can I fix it? Thank you

  12. rot

    Did you copied and pasted without reading ?
    it’s never a good idea.

    to solve your problem, comment/remove the “enforce www” part and it should work better.

    Plus search and replace the references to domain.tld with something approching your own project url
    http://localhost/testweb

    to avoid other bad behaviors, i would suggest you to look at using apache virtualhost as it is a good practise. search the web for “Apache Virtual Host”

  13. sumit derbi

    I have read this. thanks for tut. i was searching for this . i have intranet with server name unicus-billion.And my CI path for my page is:
    unicus-billion/resume/index.php/resumecontroller/load
    alernatly i have used routes also
    unicus-billion/resume/index.php/resumecontroller/load
    same as
    unicus-billion/resume/index.php/user.
    after reading i have pasted & changed it. i got following error:-
    ———
    Not Found

    The requested URL /resume/resumecontroller/load was not found on this server.
    Apache/2.2.6 (Win32) mod_ssl/2.2.6 OpenSSL/0.9.8g PHP/5.2.5 Server at unicus-billion Port 80
    ——–
    will you please help me
    to work my code simply without index.php in url.
    thanks and regards
    Sumit derbi

  14. rani patil

    i got ’404 Page Not Found’ error.plz help me .in .htaccess file .plz.
    Thanks .

  15. arion

    hi Dimas,

    i follow your totorial,
    i think i have same problem with @allis
    i have virtual host like :
    b3.menlh.go.id in directory : home/b3/www/MENLH
    this website is like the parent portal cms base on joomla

    then i want to put CI application on the same server ,
    so CI application extracted on home/b3/www/MENLH/registrasi directory

    here is my configuration :

    $config['base_url']= ‘http://b3.menlh.go.id/registrasi’;
    $config['index_page'] = ”;
    $config['uri_protocol'] =’AUTO’;

    my default controller is “main”,
    works fine when acces http://b3.menlh.go.id/registrasi

    but i get error : “The requested URL /registrasi/main/login was not found on this server. ”
    when acces http://b3.menlh.go.id/registrasi/main/login

    plis help me dimas

    thx so much :)

  16. Rangan

    Good tutorial dude. Thanks

  17. Wes Dean

    This was very helpful. Thanks for posting it.

  18. jp

    hi.
    I tried this but it keeps redirecting me to http://www.domain.tld/
    any help
    thanks

  19. paras

    how to search index file function in route directory.
    please solve the problem and get answer please quickly.

  20. ridgerunner

    Your first “welcome” rule has a problem. It matches “welcomeindex” and “welcomeindex.php” (and not “welcome/index.php”

  21. Thomas

    How to remove the controller name from the url