Codeigniter deploy index.php show 404 error - .htaccess

I just deploy my codeigniter project into hosting server. I got this problem.
By right the link should work in this -> http://test.com/quiz/test
When I deploy I need to key this then can work.
http://test.com/quiz/index.php/test
This my server hierarchy
public_html
|-css
|-js
|-index.php
|-quiz
|---application
|---system
|---index.php
|---....
|---.htaccess
This is my htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
Is that correct?

Try this in your htaccess, this works for me:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Also keep your htaccess inside quiz folder not in application folder.

Change the file names to First letter Caps and class name too.
ex: mas_unit_ctrl change to Mas_unit_ctrl

Related

htaccess internal server error rewrite not working

I have a pretty simple .htaccess file that is causing a 500 Internal Server Error but I don't know why. I am using WAMP with virtual host wdc.test, my root folder is C:\wdc, and my www folder is C:\wdc\www, links that look like this href="wdc.test/title" come up with the error when I know that it should be pulling up the index file in www
my .htaccess file looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /www/index.php [L,QSA]
thanks
It is most likely due to the reason that your DocumentRoot points to C:\wdc\www instead.
If that is indeed the case use this rule in site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Code igniter htaccess pointing to a folder while removing index.php and adding www

As the title says, I am using Code Igniter, need to point to a folder on godaddy hosting account, while removing index.php and adding www.
My current settings work for the main page only, also all the css and js files get included. However, none of the internal links work and i get 500 internal server error.
all the current settings:
In the domain settings, it is pointing to a folder on my hosting, working correctly since the main site loads.
config.php
$config['base_url'] = 'http://www.example.com';
$config['index_page'] = '';
htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
Edit: Managed to solve it, all that was missing was this line
RewriteBase /
i am not sure whether it will work for you or not but i am using it and its working fine for me.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
just paste the code in your root directory .htaccess file. Please let me know the status.

Moving codeigniter project to a new hosting provider - .htaccess and index.php

I just moved my functional codeigniter project to a new web hosting provider and am now having challenges removing the index.php from the URL using a standard .htaccess mod-rewrite. Here is the .htaccess that was working fine:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I found this discussion but I do not have root access to the apache server to make the suggested configuration change.
Using the provided .htaccess file above,
Works fine: http://www.mysite.com/index.php/plans
Doesn't work: http://www.mysite.com/plans
Any suggestions are appreciated.
If you really have to accept both forms of URLs likewise then you need two RewriteRules. Once accepting variants with then 'index.php' part and one without.
Something like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index\.php/(.*)$ index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Your question's not very clear, but a common problem with mod_rewrite rules like this is that some servers need the request to be passed as a query. I.e. you'd need to change your last line to:
RewriteRule ^(.*)$ index.php?/$1 [L]

codeigniter htaccess with multiple applications

I am using codeigniter. I have front end application and backend application like
/system/
/application/
/front/
/admin/
index.php
admin.php
.htaccess
I want my url like http://example.com/news/article1 (for site)
http://example.com/news/admin (for admin)
In .htaccess I have written
RewriteEngine On
# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin$ admin\.php [L,QSA]
# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin\/(.*)$ admin\.php/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
the front end is working fine but when I enter mydomain.com/admin it is throwing 404 not found error. Please help me.
Thanks and regards
I'm not that good with .htaccess, but from the CI website, you can use this for your .htaccess rule
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and then use routes to rewrite your urls. Much easier than trying to do it in .htaccess files

Help in configuring .htaccess to exclude a path from rewriting

I have a root folder with the following .htaccess configuration
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
What I need is, I have installed a wordpress site in a sub directory 'blog/'. Now I am able to access the home page of the blog since I have givien RewriteCond %{REQUEST_FILENAME} !-d. But clicking on a post will redirect me to the index file in root folder. How can I solve this. Please help. Thanks in advance.
Add a RewriteCond to exclude paths which begin with "blog/"
Something like (added some existant rule for context)
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?blog/
Not tested, but you get the idea

Resources