Welcome Guest, Not a member yet? Register   Sign In
Working Mod Rewrite setup
#1

[eluser]tdktank59[/eluser]
So ive found a few questions about mod rewrite as well as had a bunch of problems doing it myself.

So heres a collection of everything I found.

Is mod rewrite turned on?
First off your host needs to have mod rewrite turned on and configured properly. Since most host do by default you should be set otherwise contact them to see if you can get them to enable it.

One way to tell if it is enabled is create a file and put this into it
Code:
<?php
echo phpinfo();
?>

search the page for mod_rewrite if it shows up then its enabled otherwise it is not.

So you say your using XAMPP?
Since you are running xampp on your local machine heres how to setup mod rewrite to work.
* note: It works for me this way. If there is a better way then please post below and I will verify and update this post *

Modify httpd.conf (by default httpd.conf should be located at "C:\xampp\apache\conf")
Step1: load mod rewrite module
find the line that has this

Code:
#LoadModule rewrite_module modules/mod_rewrite.so
remove the # so it looks like this
Code:
LoadModule rewrite_module modules/mod_rewrite.so

Step 2: Allow override
find every line that has this (theres a few of them)

Code:
AllowOverride None
change it to
Code:
AllowOverride All

Setup .htaccess
create a file where you index.php file is for CI and name it .htaccess
in the file put this code

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    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.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

Make sure you have the line
Code:
RewriteBase /
point to the right location by default it will go to localhost if you are using xampp otherwise it will go the domains is located.

Configuring CI

Find the config.php file (by default "CI/system/applications/config/config.php")
now remove remove index.php from the index_page config item so it should be ""

And change the URI PROTOCOL to REQUEST_URI

The changes
Code:
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'        Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'        Uses the REQUEST_URI
| 'ORIG_PATH_INFO'    Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol']    = "REQUEST_URI";


And there you go if you modified httpd.conf you will need to reboot apache otherwise it should work now!

If it dose not work let me know and we can figure out what is going wrong.

Again this was the method with how I got it to work.. There may be a better or more efficient way to make it work. However all the methods I found on CI did not work for me.
#2

[eluser]Colin Williams[/eluser]
It's not all 100% accurate, but maybe it will help someone. For instance, AllowOverride doesn't need to be set to All for every directory, just the directory the mod_rewrite rules are set for (so, you could really just do it in the .htaccess file).

Also, CI doesn't need to use REQUEST_URI in order to work. PATH_INFO or ORIG_PATH_INFO could work just as well.

This stuff isn't magic. It either works or it doesn't work for specific reasons. The important thing is, with each change you make, to know the impact of the change and why it needs to be what you set it to.
#3

[eluser]tdktank59[/eluser]
True...

However like I said this is what I how I got it to work for myself...

For most it will be for there local dev box that they have to screw with apache so yeah.

Im still learning that sort of stuff and its making more sense but for someone who wants to get there dev box working with mod rewrite this will make it work fast and easily.
#4

[eluser]Colin Williams[/eluser]
Make sure you take the time to learn it. Knowing how your server works isn't exactly trivial.
#5

[eluser]tdktank59[/eluser]
Thats my goal lol!

Actually have a Dell PE 1850 next to me right now (off atm...) but im setting up a web server on it and learning all the little tid bits about it so its on the todo list!




Theme © iAndrew 2016 - Forum software by © MyBB