CodeIgniter Forums
Mod rewrite problem? Urls all go back to home page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Mod rewrite problem? Urls all go back to home page (/thread-16360.html)



Mod rewrite problem? Urls all go back to home page - El Forum - 03-04-2009

[eluser]diego.greyrobot[/eluser]
The weirdest thing happened when I uploaded my new website (www.donavonsreef.com)
Now only the index action of the default controller is the only one that is responding
the default controller is called home, and the only link the will show up on my new site is donavonsreef.com/home, if i try to go to donavonsreef.com/home/about, or donavonsreef.com/shop, the url will look correct but the home page will still load up. One way i got past this problem temporarily was by adding a www redirect in the .htaccess file so that any url requests that werent preceded by www. were changed to www. also the base url had to be set to be one without the www in it, then and only then would my links work and actually take me to the shop page for instance.

I've deleted all the files from my server and reuploaded them from my development server (which works perfectly) and still the links all just load up the home page. I have no idea where this problem came from or were it could be stemming from.

if i try to go to the url donavonsreef.com/shop (with or without the www) it will only load up the index action from the home controller rather than from the shop controller as its supposed to, but if i add donavonsreef.com/index.php/shop that will work.

Any other ideas of where i could troubleshoot this?


Mod rewrite problem? Urls all go back to home page - El Forum - 03-04-2009

[eluser]TheFuzzy0ne[/eluser]
Please show us your controller code.


Mod rewrite problem? Urls all go back to home page - El Forum - 03-04-2009

[eluser]mello.capinpin[/eluser]
I think your mod_rewrite is not loaded.


Mod rewrite problem? Urls all go back to home page - El Forum - 03-04-2009

[eluser]diego.greyrobot[/eluser]
Here's the code form the my default 'home' controller:
Code:
<?php
class Home extends Controller {

    function Home() {
        parent::Controller();
        session_start();
        $this->load->model('content_model');
        $this->load->model('admin_model');
    }
    
    function index() {
        $data['view_data']['top_white_box'] = $this->content_model->get_content('home_page', 'top_white_box');
        $data['view_data']['middle_white_box'] = $this->content_model->get_content('home_page', 'middle_white_box');
        $data['view_data']['top_black_box'] = $this->content_model->get_content('home_page', 'top_black_box');
        $this->load_view('home_view', $data);
    }
    
    function about() {
        $data['view_data']['about'] = $this->content_model->get_content('about_page', 'top_white_box');
        $data['view_data']['site_links_data']['links'] = $this->admin_model->get_banners(true, true);
        $this->load_view('about_view', $data);
    }
    
    function contact() {
        $data['view_data']['contact'] = $this->content_model->get_content('contact_page', 'top_white_box');
        $this->load_view('contact_view', $data);
    }
    
    function load_view($page, $vdata) {
        $data['head_data']['keywords'] = $this->products_model->get_keywords();
        $data['head_data']['description'] = "Buy Corals at Donavon's Reef";
        $data['head_data']['title'] = ucfirst(str_replace('_view', '', $page))." Donavon's Reef";
        $data['head_data']['head_items'] = array();
        
        //append view data to data
        if($vdata) $data += $vdata;
        
        $data['view'] = $page;
        //echo "<pre>"; print_r($data); die();
        $this->load->view('main_view', $data);
    }
    
}

/* End of file home.php */
/* Location: ./controllers/home.php */

I'm pretty sure mod rewrite is enabled on this server or else the site would only work if I type in index.php at the end right? also 301 redirects work fine when redirect from non-www urls.

this is what my htacess file looks like:
Code:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|swf|xml|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^donavonsreef.com
RewriteRule (.*) http://www.donavonsreef.com/$1 [R=301,L]

and here's part of my config.php file:
Code:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|    http://example.com/
|
*/
$config['base_url']    = "http://www.donavonsreef.com/";

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";

what else can i try?


Mod rewrite problem? Urls all go back to home page - El Forum - 03-04-2009

[eluser]TheFuzzy0ne[/eluser]
It sounds like you may have a route that's redirecting to the index method. Have you added any routes to the routes.php file?


Mod rewrite problem? Urls all go back to home page - El Forum - 03-04-2009

[eluser]diego.greyrobot[/eluser]
Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";

Thats the only thing in the routes.php file, it's the same as it was on my development server. I wonder what else could it be?


Mod rewrite problem? Urls all go back to home page - El Forum - 03-04-2009

[eluser]TheFuzzy0ne[/eluser]
I think that removing the QSA from your htaccess file might fix it. You're not using a query string, so it shouldn't be needed:
Code:
DirectoryIndex index.php

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond $1 !^(index\.php|images|css|js|swf|xml|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

I've also changed the second part of your code so it works with any domain, and I've put it at the top as I don't think it will ever be reached when it's at the bottom.


Mod rewrite problem? Urls all go back to home page - El Forum - 07-14-2009

[eluser]Joe L[/eluser]
Thank you very much, it really solved my problem, I spent about a week trying to find a solution to this. I'm wondering why they don't put this code in the User's Guide. Thanks again.