php - codeigniter rewrite rule leads to infinite loop -
i'm using codeigniter, , i'm getting 500 server error when try visit page. (https://test_page.com) redirects (https://test_page.com/auth/login). notice how (https://test_page.com/index.php/auth/login) still works.
- im using https://, , i'm not sure if makes difference or not.
- i have configured sites-available file domain allowoverride.
codeigniter base directory: /var/www/test_page.com/public_html
my apache error log says:
request exceeded limit of 10 internal redirects due probable configuration error. use 'limitinternalrecursion' increase limit if necessary. use 'loglevel debug' backtrace.
httpd.conf file
servername localhost <directory /var/www/test_page.com/public_html> options indexes followsymlinks multiviews allowoverride order allow,deny allow </directory>
.htaccess
options +followsymlinks -indexes <ifmodule mod_rewrite.c> rewriteengine on rewritebase /registration.naturebridge.org/ 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 ^(.*)$ /public_html/index.php?/$1 [l] </ifmodule> <ifmodule !mod_rewrite.c> errordocument 404 index.php </ifmodule>
config file:
$config['base_url'] = 'https://test_page.com/'; $config['index_page'] = ''; $config['uri_protocol'] = 'request_uri'; $config['url_suffix'] = '';
the solution
edit .htaccess include following (also remember not edit in word or rich text format editor add characters , give compilation error).
<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>
cargo-cult programming rewrite rules. codeigniter gives list of rewrites - why did have modify them. anyway, let's inspectin'.
rewritecond %{request_uri} ^system.* rewriterule ^(.*)$ index.php?/$1 [l]
your request uri start /, won't match anything.
rewritecond %{request_uri} ^application.* rewriterule ^(.*)$ index.php?/$1 [l]
same.
rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ /public_html/index.php?/$1 [l]
you'll need rewrite following:
rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ /public_html/index.php?/$1 [l]
this correctly map not directory , not file. however, mod_rewrite takes public paths , not file paths (and if did, yours wouldn't work - /public_html/ not valid linux path).
change last 1 following:
rewriterule ^(.*)$ /index.php?$1 [l,qsa]
and things should work bit better. infinite loop because mapped /blah /public_html/index.php?/blah, did not exist, tried mapping /public_html/index.php?blah /public_html/index.php?/public_html/index.php?blah , not exist...you idea.
Comments
Post a Comment