3

I want my URL's to look like: www.domain.com/controller/view/args instead of index.php?/controller/view/args. Actually, I NEVER want the url "index.php?..." to validate. Can anybody give me a hint on how to enforce this behavior, because when I do: A) redirect() or B) type in manually 'index.php'"..." the url changes to that ugly pattern.

This is my .htaccess file (I don't know if I need this file, just copy+pasted from the internet):

#http://codeigniter.com/wiki/Godaddy_Installaton_Tips/

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

This is my config.php:

$config['base_url'] = '';
$config['index_page'] = 'index.php?';
$config['uri_protocol'] = 'AUTO';
$config['enable_query_strings'] = FALSE;

And this is what changes the behaviour:

redirect('...blah', 'either location or refresh');

3 Answers 3

2

You actually need the .htaccess file in the root of the codeigniter directory(wherever index.php is). The .htaccess file is responsible for managing the rewriting of parameters. if you query yoursite.com/?controller/model, it will work the same as if index.php were there. The "?controller/..." will still be there, but index.php will not be there as long as you remember to always link to the non index.php version. The included .htaccess will work in most cases (especially with apache). You may need to modify if codeigniter is not in the root of your site(i.e. public_html/somedir/{codeigniter_goes_here}).

Sign up to request clarification or add additional context in comments.

2 Comments

Yup, the .htaccess is in the root next to the index.php. I can access both "/a/b/c" and "index.php?/a/b/c" but whenever I call "redirect(...)" it changes the url from the former to the latter (BAD).
Try changing the 'index.php?' to just '?'.
1

In addition to needing to place the .htaccess in the root of the codeigniter install (in the same place as the index.php), you'll also need to ensure that mod_rewrite is working on your Apache install, otherwise the .htaccess file will just be ignored.

Additionally, you need to set the AllowOverride directive in your Apache virtual host (see http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride) - it should be set to something like:

<VirtualHost *:80>
...
AllowOverride All
...
</VirtualHost>

You should also change:

$config['index_page'] = 'index.php?';

To:

$config['index_page'] = '';

1 Comment

Holy shiiiit... you've hit the nail on the head (crossing fingers). I have to set the ['index_page'] = '' if I am using mod_rewrite, just like the comments tell me... :-/
1

From the CI Wiki: http://codeigniter.com/wiki/mod_rewrite/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.