Welcome Guest, Not a member yet? Register   Sign In
URL Rewriting doesn't work anymore (codeigniter 2.0 official release)
#1

[eluser]DarKDinDoN[/eluser]
Hi !

I just downloaded the new version of this awesome framework ! (Thanks bye the way :-) )

I tried to update my application (from the old 2.0) but for some reasons the site broke ...
After some tests, I figured out where the problem come from :

If I do a simple installation of CI with an extra .htaccess file like this :

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

and these config vars :

Code:
$config['base_url']    = "http://example.com/";

$config['index_page'] = "";

Then accessing it

Code:
http://www.example.com/app/
or
http://www.example.com/app/welcome/

I get a 404 error codeigniter's page. By doing this the same way with the 2.0 beta (the old one), no errors at all ...

Is it normal ?

PS: I tested it on a local server...
#2

[eluser]InsiteFX[/eluser]
Code:
// Will auto set it if blank now!
$config['base_url'] = '';

InsiteFX
#3

[eluser]DarKDinDoN[/eluser]
Thanks ! Actually, I noticed that it depends of the server (local or live) ...
And I haven't fix my problem yet ...

Two very simple examples :

________________________________________________________

1. I copy the content of the CI 2.0 zip in the local server folder and in the web server root. I do nothing else (I mean absolutly nothing ...) and i run :

Code:
//For the local server
http://localhost/ -----> OK
http://localhost/index.php/ -----> OK
http://localhost/index.php/welcome/ -----> OK
http://localhost/index.php/wrong_controller_must_fail -----> OK show CI 404

//For the live server
http://www.example.com/ -----> OK
http://www.example.com/index.php/ -----> OK
http://www.example.com/index.php/welcome/ -----> OK
http://www.example.com/index.php/wrong_controller_must_fail -----> Failed to show the CI 404

-> Local server : nothing wrong.
-> Live server : always display the main controller even when it must fail and call the 404 ...

2. For the second example I set the 'index_page' var to :

Code:
$config['index_page'] = '';

And add this '.htaccess' file to the root :

Code:
RewriteEngine On

RewriteBase /

RewriteCond $1 !^(index\.php)
RewriteRule ^foo/(.*)$ /index.php/$1 [L]

and i run :
Code:
//For the local server
http://localhost/foo/ -----> FAIL CI 404
http://localhost/foo/welcome/ -----> FAIL CI 404
http://localhost/foo/wrong_controller_must_fail -----> OK but certainly not cause of the wrong parameter

//For the live server
http://www.example.com/foo/ -----> OK
http://www.example.com/foo/welcome/ -----> OK
http://www.example.com/index.php/wrong_controller_must_fail -----> Failed to show the CI 404

-> Local server : Always show the CI 404.
-> Live server : always display the main controller even when it must fail and call the 404 ...

________________________________________________________


I never had these issues with the 2.0 CI DEV. So what the ... ? Did I miss something ?
#4

[eluser]DarKDinDoN[/eluser]
Since I solved the problem (I had to activate the PHP 5.3 on OVH'server ) I try to optimize the '.htaccess' to handle multiple applications.

If I have only one app in the root server :

Code:
SetEnv PHP_VER 5_TEST ----> activate the php 5.3

RewriteEngine On

RewriteBase /

Options +FollowSymLinks -Indexes

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L]

Now if I have three apps in the root server (they share the same system but note the same app folder) : index_foo.php, index_bar.php, index.php

Code:
SetEnv PHP_VER 5_TEST ----> activate the php 5.3

RewriteEngine On

RewriteBase /

Options +FollowSymLinks -Indexes

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

RewriteRule ^foo(.*)$ index_foo.php/$1/ [L] //foo app, http://www.example.com/foo

RewriteRule ^bar(.*)$ index_bar.php/$1/ [L] //bar app, http://www.example.com/bar

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L] //main app, http://www.example.com/

Is this all correct ? I mean, it is running fine, but I have the feeling I forgot something ...
#5

[eluser]Spir[/eluser]
I'm on OVH as well. All my app use the same application directory but I load conf depending of URL. It works for me :

Code:
SetEnv PHP_VER 5_TEST
SetEnv REGISTER_GLOBALS 0

# some optimisation
AddOutputFilterByType DEFLATE text/css text/plain text/xml application/javascript application/json
Header unset ETag
FileETag none

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|robots\.txt|img\/|css\/|js\/|favicon.ico)
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 /index.php
</IfModule>

On OVH you can target your URL to diferent folder. Why don't you make your different app use a different index.php but same system folder? Would be easier Smile
#6

[eluser]DarKDinDoN[/eluser]
Thanks Spir, since I use very different apps, I prefer separate the application folders (and I always use the same system folder for all the apps). But, using the index.php to determine wich URL matches to the requested app rather than the .htaccess is a good idee !


i'll work on it Wink
#7

[eluser]DarKDinDoN[/eluser]
Ok, I'm dealing with the multiple apps and only one index.php ...

Here is the server's root folder :

Code:
./system/
./app_foo/
./app_bar/
./app_default/
./index.php
./.htaccess

and my .htaccess to avoid the index.php :

Code:
RewriteEngine On

RewriteBase /

Options +FollowSymLinks -Indexes

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

And in the index.php, I manage to load the right app folder depending on the first url segment :

Code:
$url= $_SERVER['REQUEST_URI'] ;
   $app_resquested = explode("/", $url);

    switch ($app_resquested[1]) {
        case "foo":
            $application_folder = "../applications/app_foo";
            break;
        case "bar":
            $application_folder = "../applications/app_bar";
            break;
        default:
            $application_folder = "../applications/app_default";
    }

So, if I run :

Code:
http://www.example.com/     ---&gt; should load the default app
http://www.example.com/foo  ---&gt; should load the foo app
http://www.example.com/bar  ---&gt; should load the bar app


The right apps are displayed, but for the foo and bar apps, I get a CI 404 error ... did I miss something ? again ? :p
#8

[eluser]ipsod[/eluser]
URL rewriting isn't working for me, either. I've tried several .htaccess files I found posted in the forums and wiki, and none work. I have a fresh Applications folder, and no matter what, I'm sent to the default page. No error pages, nothing, just default page, every time.

It works when I add in the index.php. Just doesn't work when I'm trying to use a .htaccess rewrite.

Help please!
#9

[eluser]Vanitas[/eluser]
I think I also have problem with this.
Since I created .htacces file my web page is not loading any pictures, it's strange because css styles are working.
I can't access any picture even by typing direction in adress bar.

@EDIT
I'm using CI Reactor but it may be the same problem.
#10

[eluser]d1a8lo24[/eluser]
Got the same problem, but I did figure out something in the 2 versions from the core and reactor.

I still havent check all the files but I did find out that when replacing the system folder from reactor to the core 2.0 everything went back to normal, except for a few little glitches or I guess features that reactor suppose to offer like the ability to not use the base_url and to let reactor figure it out in the core you do have to specify it.

There are 6 files that are very different from the core version and are as follow:

system/core/config.php
system/core/input.php
system/core/lang.php
system/core/loader.php

and the ones that I think are causing the problem.
system/core/router.php
system/core/uri.php

I have only check this folder and I didn't have time to really check the code and see where the problem is, if I can figure it out.

But if you don't have the time just change the reactor system folder with the core system folder.

https://bitbucket.org/ellislab/codeigniter




Theme © iAndrew 2016 - Forum software by © MyBB