Welcome Guest, Not a member yet? Register   Sign In
mod_rewrite - I cant seem to get it to work.
#1

[eluser]symvar[/eluser]
Hi all,

I've been trying to get started with codeigniter for a few days now but i'm stuck at removing the index.php from the url's.

I tried numerous different suggestions/configs found either on these and other forums. And it seems i just cant get it to work.

All i know for sure is that mod_rewrite is available on my webserver and .htaccess files can be used. I know this because i have some mod_rewrite testscript running.

CI is running in a subfolder on my webspace like "www.website.com/ci".

I couldnt help having a laugh at this part of the user guide:

Quote:By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article

You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

Could someone maybe give it a try to help me out? I'll make sure to answer any question as clearly as possible.

Cheers,
symvar
#2

[eluser]guidorossi[/eluser]
Did you remove index.php from $config['index_page'] on config.php

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

That's the first thing...

and on the .htaccess file I use something like:
Code:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /ci_install_folder
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
  ErrorDocument 404 index.php
</IfModule>
#3

[eluser]oldmatt[/eluser]
Additionally, you might need to change the value of:

Code:
$config['uri_protocol']    = "AUTO";

to one of the other settings in your config.php file.

I have found that every now and then, you'll run into a server that needs a different setting.
#4

[eluser]symvar[/eluser]
[quote author="guidorossi" date="1299733896"]Did you remove index.php from $config['index_page'] on config.php

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

That's the first thing...

and on the .htaccess file I use something like:
Code:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /ci_install_folder
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
  ErrorDocument 404 index.php
</IfModule>
[/quote]

Thanks for the reply m8,

For the occasion i uploaded a fresh copy of CI to www.wicservices.nl/ci

Like you said i removed the index.php in the config file. I'd like to mention that i didnt forget in my previous attempts.

The code in my .htaccess is now:

Code:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /ci
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
  ErrorDocument 404 index.php
</IfModule>

Please note that the Rewritebase is now set to /ci as this is the directory ci is installed in.

At this moment i'm not seeing any action from mod_rewrite but i will also try the suggestion in the post above this. Maybe that can get us somewhere.

Cheers


ps.

The mod_rewrite testscript can be found on http://www.wicservices.nl/test/rewrite.php
the code used here is:
Code:
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
#5

[eluser]symvar[/eluser]
[quote author="oldmatt" date="1299745652"]Additionally, you might need to change the value of:

Code:
$config['uri_protocol']    = "AUTO";

to one of the other settings in your config.php file.

I have found that every now and then, you'll run into a server that needs a different setting.[/quote]

Hi Oldmatt,

I tried all the settings. The only thing i noticed was that with ORIG_PATH_INFO i get a 404. And with the other settings the index.php is just sitting in the adress bar Smile

I will try all the different settings in future attempts to tweak the .htaccess

Cheers,
Symvar
#6

[eluser]guidorossi[/eluser]
[quote author="symvar" date="1299777892"]
ps.

The mod_rewrite testscript can be found on http://www.wicservices.nl/test/rewrite.php
the code used here is:
Code:
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
[/quote]

uhm...to be 100% shure you have the mode_rewrite running just make a phpinfo() and see if under apache2handler > Loaded Modules is mode_rewrite...
#7

[eluser]symvar[/eluser]
Hm, i checked the phpinfo before and mod_rewrite is not there.

www.wicservices.nl/info.php

I was in doubt as well about this so i called the webhost.. they told me that mod_rewrite is enabled on all unix/linux platforms. This together with the little testscript convinced me that is was installed.

Now i dont know for sure anymore Smile Why do you doubt the testscript?

Cheers
#8

[eluser]harpster[/eluser]
I'm pretty new at CI and just ran into this same problem. After doing some research I found this link that helped and is not that different from what was posted above but this mod rewrite stuff is greek to me. http://www.marioawad.com/2009/05/19/url-...deigniter/

I ended up doing the following and now it works at least on my MAMP server.

1. Change the config file to remove the index.php
$config['index_page'] = '';


2. Add this .htaccess file added to root (there the ci system folder is located)
Code:
RewriteEngine On
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

3. At this point it still didn't work but I realized I had renamed the Codeigniter directory from ci to "fitlog" which is the name of my app. After I modified the .htaccess file to change the two references from /ci/ to /fitlog/ it works.

I haven't tested on a live web server yet but will do that in a day or so and post back if I had to do any changes to get it to work there. I really don't understand why ci uses that index.php as part of the visible URL because it seems everyone wants to got rid of that index.php part. Wish ci would just make it standard so we didn't have to fool with having to remove this.
#9

[eluser]InsiteFX[/eluser]
A lot of users are doing this, but it depend on the OS:
Code:
<IfModule mod_rewrite.c>

Now here is one problem, on Windows systems it is:
Code:
<IfModule mod_rewrite.so>
// not .c

Best thing is to leave it off unless you really need it!

InsiteFX
#10

[eluser]symvar[/eluser]
Thanks for the suggestion Harpster,

I'm still trying to find the correct configuration But atleast i have proove that mod_rewrite really is available as i noticed some rewrite stuff going on (just no the correct) while trying different configurations.

Tongue

Just to make sure that i understand the function of mod_rewrite for codeigniter, could someone confirm this?
If i go to "http://www.wicservices.nl/ci/index.php/welcome" mod_rewrite should remove index.php/ right?

Cheers,
Symvar




Theme © iAndrew 2016 - Forum software by © MyBB