CodeIgniter Forums
remove index.php from urls using apache httpd.conf - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: remove index.php from urls using apache httpd.conf (/thread-32769.html)



remove index.php from urls using apache httpd.conf - El Forum - 08-04-2010

[eluser]omx[/eluser]
Hi, have viewed the wiki and after extensive googling I still can't get this to work...

Have inserted the following into my httpd.conf file (and yes mod_rewrite.so is enabled)

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

With this enabled I get a 404 when I point to:

http://localhost/CodeIgniter/index.php/welcome

Any ideas?

Cheers!


remove index.php from urls using apache httpd.conf - El Forum - 08-04-2010

[eluser]n0xie[/eluser]
Try to add this and see if this makes a difference
Code:
RewriteBase /CodeIgniter/

Also take a look here: http://codeigniter.com/wiki/mod_rewrite/


remove index.php from urls using apache httpd.conf - El Forum - 08-04-2010

[eluser]omx[/eluser]
Added that line and apache won't even start...


remove index.php from urls using apache httpd.conf - El Forum - 08-04-2010

[eluser]danmontgomery[/eluser]
To expand on what n0xie said, you also need to remove the leading slash from index.php. You also should get rid of all of the /s in your RewriteCond line

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} !^(index\.php|img|js|css|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Depending on your host you may also need to add a ?:

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

If apache won't start it's giving an error, to know that error would be much more useful then "it won't start".


remove index.php from urls using apache httpd.conf - El Forum - 08-04-2010

[eluser]omx[/eluser]
Ok, in the end I just enabled .htaccess files to override conf and got it to work.

Tried several permutations, how can I remove the CodeIgniter bit from the url?

Code:
RewriteRule ^(.*)$ /CodeIgniter/index.php?/$1 [L]
has no effect...

So I end up with

http://localhost/welcome

instead of

http://localhost/CodeIgniter/welcome

Thanks!


remove index.php from urls using apache httpd.conf - El Forum - 08-04-2010

[eluser]bretticus[/eluser]
Code:
RewriteBase /CodeIgniter/

Depends on where your htaccess file is located. You should be able to use:

Code:
RewriteBase /

if your htaccess file is in the CodeIgniter folder.

If you have access to your apache config files (httpd.conf) then use virtualhosts and directory apache directives to specify exactly which directory (folder) the rewrite base refers to (plus it's much faster for apache.)

Oh, and make sure that you have mod_rewrite enabled (reason for the error perhaps.) You can check with a simple phpinfo() call (look for apache2handler.)