I recently started using codeigniter, and I've got it hosted on Bluehost here: http://dev.fuelingtheweb.com/codeigniter/.
If I included index.php in the path like this: /codeigniter/index.php/hello, everything works fine, but if I try to access the page without index.php like this: /codeigniter/hello, I get a 500 Internal Server Error. I have tried numerous .htaccess options, but nothing seems to work.
Currently, my .htaccess file is locating here: /codeigniter/.htaccess and it includes the following code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /codeigniter/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ codeigniter/index.php/$1 [NC,L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Also, my config file (/codeigniter/application/config/config.php) includes the following:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I tried all 5 protocol options with no success.
Any help with this would be greatly appreciated.
Did you try the one from user guide?
https://www.codeigniter.com/user_guide/general/urls.html
Related
I have a Laravel 4 app deployed on shared Hostgator server.
When I navigate to:
http://mydomain.com/laravel/public/
I can see the Laravel splash screen.
but when I try to access any other route to, say, /users or /posts I am getting
Internal Server Error 500
http://mydomain.com/laravel/public/posts
Controller:
public function index()
{
$posts = $this->post->all();
return View::make('posts.index', compact('posts'));
}
In Routes.php:
Route::resource('posts', 'PostsController');
I use Jeffrey Way's Generator to scaffold the posts entity.
The same works fine on my local machine. Controllers don't contain any logic, they only output the fetched data.
Error logs are empty.
Any ideas what to check? .htaccess, maybe?
Here is what I have there:
AddType application/x-httpd-php53 .php
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
As mentioned in comments, a 500 error without a corresponding log file entry from the application logger is likely an .htaccess file issue.
Since the OP found the issue is related to the rewrite (and not the directive to use php 5.3):
Since this is probably a common issue on Hostgator, you should check with their help docs.
However, my first stab at a fix would be to add a RewriteBase directive:
RewriteBase /
So it would look like:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Note that this assumes you're running the web application form the web root and not a sub-directory.
I have a directory structure like root/user/confirm/index.php
I want to make redirect like
Redirect this url
http://www.site.com/user/confirm/ASd2sasda4ass
To this
http://www.site.com/user/confirm/index.php?confirm=ASd2sasda4ass
I am trying this way
RewriteRule /user/confirm/([^A-Za-z0-9])$ /user/confirm/index.php?confirm=$1 [L,QSA]
It redirects this url properly
http://www.site.com/user/confirm/index.php/ASd2sasda4ass
To
http://www.site.com/user/confirm/index.php?confirm=ASd2sasda4ass
But not working for this url without index.php
http://www.site.com/user/confirm/ASd2sasda4ass
It shows 404 not found error
Please see and suggest any possible way to do this.
Thanks.
UPDATE
Complete codes
Options +FollowSymlinks
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteRule /user/confirm/([^A-Za-z0-9])$ /user/confirm/index.php?confirm=$1 [L,QSA]
</IfModule>
Try this (without confirm.php in the url. You shouldn't need it anyway):
RewriteRule ^user/confirm/(.*)/? user_confirm.php?confirm=$1 [L]
I solved this issue by removing this rewrite rule from root .htaccess
RewriteRule ^/user/confirm/([^A-Za-z0-9])$ /user/confirm/index.php?confirm=$1 [L,QSA]
And placing another .htaccess file in confirm directory to hide index.php and processing query parameter there with following codes.
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?confirm=$1 [L]
</IfModule>
And now its working without index.php in url. Hope this helps others too with same issue.
So I'm having a weird problem with .htaccess file and codeigniter. I have a wamp server on my local machine and there it works as expected. I have folders like that wamp/www/my_app and in my_app folder i have .htaccess file like that:
ErrorDocument 404 /index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
And in mine config.php gile i have:
$config['base_url']='';
$config['index_page']='';
$config['uri_protocol']='AUTO';
So i tried uploading that project to debian server on link like apps.myserver.com/my_app. I put my app to folder var/www/my_app. But the trick is that it doesn't work.
I have tried changing uri_protocol to all 5 options but no change. I also tried putting .htaccess file to var/www instead of var/www/my_app but no change either.
I keep getting that stupid 404 Not Found error when i try to access controlers without index.php prefix.
Any ideas?
EDIT: I checked phpinfo on server and found that mod_rewrite is in loaded modules.
The mod_rewrite module can have a couple different extensions. Your Debian server might use mod_rewrite.so instead of mod_rewrite.c.
That said, if you know mod_rewrite is enabled, and your application isn't being widely distributed and needs to check for it, you can safely eliminate the if checks.
You mentioned commenting out everything except lines 3 and 7 -- you commented out the RewriteBase definition, which broke stuff.
Try something simple, and work from there:
RewriteEngine On
RewriteBase /my_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Also, one variation you can do if an .htaccess is being weird, is to change everything after index.php to a query string. Note the ? here:
RewriteRule ^(.*)$ index.php?/$1 [L]
You may or may not to change the uri_protocol config setting in CodeIgniter. My guess is you specifically won't, but it's info for others who are having .htaccess issues.
I recently moved a functional codeigniter application to a new hosting provider and am running into what I think are challenges similar to this topic. To summarize, my $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO'] values are not being set unless I include the index.php reference in the URL. I'm assuming this means that my .htaccess may be the culprit or a combination of issues. Here's what I've done:
I edited codeigniter's config.php file to remove the index.php reference
$config['index_page'] = '';
I created the following .htaccess file to remove the index.php from the URL
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I've toggled between the RewriteRule [L] and [QSA,L] values and get the same behavior.
In the config.php file, I set the following value
$config['uri_protocol'] = 'PATH_INFO';
Using this configuration above, attempting to open www.mysite.com/test/1234 simply opens www.mysite.com. But when I open www.mysite.com/index.php/test/1234, the $_SERVER[PATH_INFO] => /test/1234, but only opens www.mysite.com.
When I switch back to:
$config['uri_protocol'] = 'AUTO';
I can access www.mysite.com/test/1234 (without needing /index.php/), but the $_SERVER[PATH_INFO] value is not being set.
Any suggestions are appreciated.
There is no reference to PHP version in development and production environment, but at first glance I would try changing the cgi.fix-pathinfo setting:
http://php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
if php.ini editting is available.
Having issues removing index.php? from the URL:
http://localhost/index.php?/reset_password
With htaccess file:
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
CI Settings:
$config['uri_protocol'] = 'AUTO';
I looked at the other threads on here with similar problems but none of their htaccess files work. Am I missing a setting?
I've never seen that .htaccess setup before, although it may work. I've used this for every CI project I've done, give it a try:
<IfModule mod_rewrite.c>
RewriteEngine on
# If the start of the URL doesn't match one of these...
RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads)
# Route through index.php
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Add don't forget this in config.php:
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
And remember: This will not "remove" index.php from your URL automatically, but rather route the request through it if it isn't present. If you have hardcoded links with index.php in them, they'll have to be changed or you'll need additional .htaccess configuration. If you are using the CI url functions like base_url(), site_url(), and anchor(), they won't use index.php if you have it blank in your config above.
This code works for me:
If name of my site is codeIgniter_ci_intro
I used code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /codeIgniter_ci_intro//index.php/$1 [L]
and I changed in config.php
$config['index_page'] = '';