开发者

mod_rewrite for codeIgniter

Has开发者_高级运维 anybody in the history of the internet and web development, been able to get rid of the "index.php" with mod_rewrite in codeIgniter.

I've been trying for several days now and nothing seems to work.


I'm using this one (in .htaccess file):

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

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

Not sure where I got it but it works for my codeigniter install, local and live. Don't forget to set $config['index_page'] = ''; in your config file.


For mod_rewrite use the following in your .htaccess file

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

If your codeigniter instance is running in a subdirectory then use the rewrite base command before the RewriteRule

RewriteBase /subdirectory/

Then set

$config['index_page'] = '';

In the config file.


You might have your .htaccess file in the wrong place. CodeIgniter has a default .htaccess placed in the applications folder, which I mistakenly took for the one I should edit.

You actually need to create a new .htaccess under the root folder. So not code_igniter/applications/.htacces...but code_igniter/.htaccess

Hope this helps.


Yes, I configured it under Linux using the instructions from here. However, I configured it via httpd.conf instead of using .htaccess.


I have used the settings provided above and they always worked - unless I did not have mod_rewrite enabled.

If you are having issues check to ensure you have mod_rewrite enabled. If you do not it will not matter what you put into .htacess or your Apache config

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜