4
votes

I'm having trouble getting mod_rewrite to work with CodeIgniter. I'm running apache 2.4.

My web root is /Users/Jason/Development/www

This is the code I currently have in my .htaccess file located in the same directory as my main index.php file.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /myapp/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

What am I doing wrong? I keep getting a 404 page saying the requested URL was not found on this server.

1
Check webserver logfiles - Charlotte Dunois
Is your app located in www/myapp? - Mike Rockétt
Is apache mod_rewrite module enabeld ? - Alankar More
Check AllowOverride on Apache configure. This allows htaccess to run. To test if htaccess works properly, type something wrong in it (Ex: abcdef at the beginning of htaccess). If you got an 500 error, htaccess is working, if error is still 404, I am sure you should find AllowOverride to enable it for your DocumentRoot. - Than Ngo Hoai
Mike, yes, it is located there. - Jason Ayer

1 Answers

5
votes
Options -Indexes +FollowSymLinks

RewriteEngine On
RewriteBase /

 # exclude any paths that are not codeigniter-app related
RewriteCond %{REQUEST_URI} !^/server-status
RewriteCond %{REQUEST_URI} !^/server-info
RewriteCond %{REQUEST_URI} !^/docs

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<IfModule mod_php5.c> 
    RewriteRule ^(.*)$ index.php/$1 [L]    
 </IfModule>    

# the following is for rewritting under FastCGI
<IfModule !mod_php5.c>    
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Base on sigmoid https://www.npcglib.org/~stathis/blog/2013/08/12/apache-tip-rewriting-urls-with-apache-2-4-php-fpm-mod_fastcgi_handler-codeigniter/