Welcome Guest, Not a member yet? Register   Sign In
Mod rewrite problem
#1

[eluser]Unknown[/eluser]
I've made a website that works without problems on my localserver, but when I upload the site to my webserver it seems like the mod rewrite doesn't work for some reason.

my .htaccess:

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

in my main controller i access the uri in this way. (debugging)

Code:
$id = $this->uri->segment(3);
echo "$id";

But it doesnt echo anything. If I do an uri->segment(2) it echos "main".

If you look at http://www.findareacode.org/index.php/main/main/2xx/ it displays everything correctly.
But if you go to the mod rewrite adress: http://www.findareacode.org/2xx/ there is errormessages, and it seems like the variables from the controller hasn't been sent to the view file. (Most probably because the uri->segment(3) is void)

Any thoughts?
#2

[eluser]bretticus[/eluser]
Don't know if you've changed anything since this post but I see a mere notice (not an error.)
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: content_type

Filename: views/main_view.php

Line Number: 184

That just means you have a variable in your view that you haven't initialized in your view nor your controller that calls it.

That page is calling your main_view.php page what makes me assume your rewrite is working fine you just have error handling "turned all the way up." Which you shouldn't for a production website. See CI Error handling and error_reporting()
#3

[eluser]bretticus[/eluser]
I think I may have answered too fast (although you still may want to change your error reporting levels when going live yet.) You have to actually USE the 3rd segment if you are going to get data from it. That means the complete path to the controller and method in the URL. Otherwise codeigniter will assume you want the 2xx controller index method (which I'm sure you don't have.) This can also be accomplished through routing.
#4

[eluser]Unknown[/eluser]
Thanks for your answer!

Quote:That just means you have a variable in your view that you haven’t initialized in your view nor your controller that calls it.

This notice, happens because I dont get the 3rd segment to my main controller, and that leads to that the variable doesn't initialize.

Quote:You have to actually USE the 3rd segment if you are going to get data from it. That means the complete path to the controller and method in the URL. Otherwise codeigniter will assume you want the 2xx controller index method (which I’m sure you don’t have.) This can also be accomplished through routing.

What do you mean with USE? (I dont understand).

To debug I now have an "echo $this->uri->total_segments();" in the main controller. This outputs the number shown at the top of the page. (example)

This output is 2 whatever number of segments I but in the url. i.e. findareacode.org/2xx/test/test/ just get 2 as output, instead of 4.

The strange thing is that it works fine on my local WAMP-server.
#5

[eluser]bretticus[/eluser]
What I mean is that CI cannot get the variable for the 3rd segment unless it's in that place actually. For example, to use it your URL should be (with the rewrite set):

http://www.findareacode.org/main/main/2xx/

Notice how 2xx comes in the 3rd segment of the URL? I noticed that with that URL it still doesn't work like the first URL example though. Have you removed index.php from index_page in your config.php file?

$config['index_page'] = "";




Theme © iAndrew 2016 - Forum software by © MyBB