Welcome Guest, Not a member yet? Register   Sign In
Help with simple routing please?
#1

Routing is my weak point, Im still not clear how it works although I read the docs many times. Anyhoo.

This is my .htaccess file
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|woff|eot|img|css|js|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

This is my controller:
Code:
class Tlc extends CI_Controller
    public function view($page='index')
    {
        if ( ! file_exists(APPPATH.'/views/tlc/'.$page.'.php'))
        {
            // Whoops, we don't have a page for that!
            show_404();
        }
         else
         {
            $this->load->view('tlc/templates/header.php');
            $this->load->view('tlc/'.$page);  
            $this->load->view('tlc/templates/footer.php');  
        }

And this is my routes.php
Code:
$route['default_controller'] = "tlc/view";
$route['/([a-z]+)'] = "tlc/view/$1";
$route['404_override'] = '';

I have my view files in views/tlc folder.

When you go to main page deltadigital.ca - everything is fine, but when you click deltadigital.ca/about-us or other similar menu items it doesnt work. It only works with full url i.e.

http://deltadigital.ca/index.php/tlc/view/about-us
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#2

I just compared with your rewrite rules with the ones that I am using. This particular line, I am using $0 instead of $1

RewriteRule .* index.php?/$0 [PT,L]

Can you try this and see if it works?
Reply
#3

(This post was last modified: 06-12-2015, 07:56 AM by lexxtoronto.)

Nope, still doesn't work, but thanks anyway as I at least I know where to look for a problem. I tried this:

Code:
RewriteRule ^(.*)/index/?$ $1 [L,R=301]

And instead of 500 server it's just giving me my webhost 404 page, which is a good sign I guess.
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#4

I'm using _remap instead of custom routes with routes.php, this method give me more wave of customization.
NexoPOS 2.6.2 available on CodeCanyon.
Reply
#5

Thanks, I will have to look into that. But for now I guess I will just read more on rewrite rules.
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#6

Still can't make it work. What are my options now? Do I just hardcode it in .htaccess similar to this?

Code:
RewriteRule    ^pet-care/?$    pet_care_info_01_02_2008.php    [NC,L]
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#7

You original .htaccess should be fine.

In your routes, though, the second one doesn't look quite right:
Code:
$route['/([a-z]+)'] = "tlc/view/$1";

You may want to remove the slash (/) in the route key:
Code:
$route['([a-z]+)'] = 'tlc/view/$1';

or to :any:
Code:
$route['(:any)'] = 'tlc/view/$1';
Reply
#8

Thank you, but still no luck. I tried both:

Code:
$route['([a-z]+)'] = 'tlc/view/$1'; and $route['(:any)'] = 'tlc/view/$1';

And also tried removing it altogether, doesnt work.

Also if I use the rewrite rule without a leading slash its giving me 500 server error

Code:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

If I use it with a slash its giving me my webhosts 404

Code:
RewriteRule ^(.*)$/index.php?/$1 [L,QSA]

I tried other modifications of this rule online and it would give me CI 404 page.
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#9

It was a problem with 1and1 host. So FIY 1and1 not good for Codeigniter. I tried a different host and it works just fine. I can't believe I wasted so much valuable time.
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB