Welcome Guest, Not a member yet? Register   Sign In
Default Controllers & mod_rewrite
#1

[eluser]underskor[/eluser]
Hey lads,

I'm having trouble getting my head around mod_rewrite and default controllers. Well, mainly mod_rewrite, so I've been just trying various .htaccess examples provided on the forums and other CI resources (user guide, tutorials etc).

Say I have my default controller (content_serve), and I have functions in it which build the various pages of my site (blog, for example). What .htaccess rules do I need to allow me to reference the controller's functions (AKA, build my pages) without index.php? It seems that I can't reference any of it's functions without it being present in the URL?

Ultimately, I want something like the following:
Code:
.com/index.php/content_serv/blog
to
Code:
.com/blog

.htaccess:
Code:
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /pdm/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

Alternatively, should I be using a separate controller for each page? It would solve my problem, but it seems like a waste to me when it can be done in one controller. Then again, I'm the one asking for help. :cheese:
#2

[eluser]cozzmyn[/eluser]
I think you should use routes
http://ellislab.com/codeigniter/user-gui...uting.html
#3

[eluser]underskor[/eluser]
Actually I think I'm going to have to use separate controllers for each page as that will make the following easier:
Code:
.com/blog/read/1

Wish I'd had that revelation a few days ago, would've saved me so much thinking. Even so, why is it that you can't reference the default controllers functions without the default controller being in the URL?

Thanks for your reply, Cozzmyn.
#4

[eluser]cozzmyn[/eluser]
Quote:Even so, why is it that you can’t reference the default controllers functions without the default controller being in the URL?

if the default controller functions would be available in the URL by default like you said, without the controller name, then you will not be able to create other controllers that have the same name as those functions. If you really want it, you still can achieve this by using that URI routing feature.

Cheers!
#5

[eluser]underskor[/eluser]
It all makes sense now. Smile

Thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB