Codeigniter 404 page not found - apache

I have been developing a Codeigniter website locally for with a WAMP server on Windows, everything working fine. I uploaded the files to a Ubuntu server to a virtual directory and configuration the URL and .htaccess. The rewrite rule works like it should but now I get 404 when I try to access the site or any other controller link. The logs state that it cannot find the controller, I checked the files to make sure they were uploaded correctly.
At this point and I at a loss, I have a hunch that it is a configuration issue with Apache but I have checked all the configs that I know. What would cause a 404 error?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

You have activated the module rewrite? If not, turn it on and restart wamp.
Also try to put index.php before the controller, may resolve the problem.

In CI 3.0, All Class names must have the first letter capitalized with the rest of the name lowercase.
Example: Where Model_name is the name of your class, this is how the class should be;
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
}
Then, the model should be loaded like this in the controller;
$this->load->model('user_model');
Please refer to this link: http://www.codeigniter.com/userguide3/general/models.html

Related

Apache RewriteRule pattern

I writing an .htaccess file for the web resources management.
I would like to this pattern of URI to use for static resource
^.*/web-console/static/(.*)$
And, my RewriteRule is below.
RewriteRule "^.*/web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]
And, I request below URI
http://myhost/shop/web-console/static/css/default.css
But the Apache server hasn't match URI.
And if I delete "/web-console" Apache works fine.
Below is the RewriteRule
RewriteRule "^.*/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]
What is a problem?
Appendix
this is my directory structure
web base - /data/web
site base - /data/web/shop
htaccess - /data/web/shop/.htaccess
router script - /data/web/shop/route.php
static resources - /data/web/shop/resources/floworks-web-console-1.0/static
css file - /data/web/shop/resources/floworks-web-console-1.0/static/css/default.css
So, I wish response static resources if URI is started /shop/web-console/static
And, other case is pass to router script using "RewriteRule .* route.php [L]"
You should be able to do it like this. If you have this .htaccess in a sub folder shop, you should add rewritebase.
RewriteEngine On
RewriteBase /shop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule "^web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [L]
I found myself.
RewriteRule "web-console/static/(.*)$" "resources/floworks-web-console-1.0/static/$1" [END]
I'd change that flag from L to END
Thanks.

Remove "/public" from Laravel route

I have the project URL as -
http://localhost/project-name/user/public/xxx
I want to change it to -
http://localhost/project-name/user/xxx
I have tried the usual solution available on internet but still no luck. These are htaccess files after going through few solution.
1. project-name/.htaccess
Options -MultiViews
RewriteEngine On
# Check what redirect trailing slash does
# Redirect Trailing Slashes...
# Handle Front Controller...
RewriteRule ^(.*)$ public/$1 [L]
2. project-name/public/.htaccess
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
What is the exact solution for this problem?
Since you don't have permissions to point virtual host to your laravel public folder, I would suggest you:
For Laravel 5, 1) move all your files in the public folder into project root, public folder is not needed anymore and 2) update the original index.php like so:
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
For Laravel 4, you also need to edit value of "public" in the array in /bootstrap/paths.php.
This should achieve what you want. Hopes this helps.
Having said that, try to host your app in VPS where you have full control on everything :)

Symfony2 htaccess mod rewrite issue

I've been having this issue for quite some time. Right now we are using a shared hosting plan and have four domains, one of which points to a symfony project. My goal is simply to omit having the app.php included in the URL. Without any .htaccess applied, all domains work flawlessly and when trying to navigate to the symfony domain I simply get a directory listing instead of having the page render, unless I include the app.php in the URL.
When applying the below htaccess, all non-symfony related domains show a 500 error and the one symfony related domain renders successfully, without the app.php in the URL. My goal at this point is to modify the htaccess so that all non-symfony related domains render successfully as they did before, while still maintaining the below .htacces to omit the app.php from the Symfony related project.
I appreciate any suggestions on how to resolve this issue. Thanks in advance!
.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
Replace the line :
RewriteCond %{REQUEST_FILENAME} !-f
With :
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

Apache mod_rewrite usually works, but won't work in this folder -- what's wrong?

I have an Apache web server that usually handles mod_rewrite fine. I have a directory called /communications/q/ and I want to rewrite any URI to insert "index.php" before the rest of the entered URI.
For example, /communications/q/something/else should actually serve communications/q/index.php/something/else. It's the standard PHP CodeIgniter setup.
I placed a .htaccess file in the /q/ directory and put the following in it:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
When I even try to go to /communications/q/, I get a 404 Not Found error. Which makes no sense at all because if I comment the .htaccess stuff out, I get the index.php page if I go to /communications/q/, but with the code, I get 404 Not Found.
Anyone spot what I'm doing wrong?
FYI I have a controller called hello, so technically /communications/q/hello should work, but it's a 404, also. But with .htaccess commented out, /communications/q/index.php/hello works fine.
..
==== ADDED NOTE #1 ====
Using CodeIgniter, I should be able to call controllers and functions using the URI structure. So I have a controller called welcome, actually, and then a function called index() which is the default, and a function called hello().
The way CI works, I would write /communications/q/index.php/welcome and I would get the output of the index() function from the welcome controller. And in fact, this works perfectly right now.
Unfortunately, having that weird index.php in the URI is unwieldy and unnecessary, so CI suggests using .htaccess to allow the URI to omit that section of the URI and silently reenter it in the background, using mod_rewrite.
When I add the RewriteRule above, however, it doesn't work. So:
/controller/q/welcome returns a 404 error when it should return exactly the same thing as /controller/q/index.php/welcome. That's the problem. Shouldn't the RewriteRule above make that work?
..
The substitution in a RewriteRule is relative to the DocumentRoot. Based on this, I'd suggest you try:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /communications/q/index.php/$1 [L]
The answer was in the CodeIgniter wiki, in the end. I replaced my .htaccess code with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /communications/q/
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# When your application folder isn't in the system folder
# This snippet prevents user access to the application folder
# Submitted by: Fabdrol
# Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
And everything worked perfectly. The major relevant change, I think, was adding a ? to the RewriteRule after index.php -- does anyone understand why that's necessary?
Source: http://codeigniter.com/wiki/mod_rewrite/

Use symfony 1.4 without changing apache configuration

Is it possible to set the /web directory as webroot without changing apache configuration file?
I tried using the following .htaccess code, but if i go to localhost/module/, it displays 404 error. But if i go to localhost/web/module/ then everything works.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule sf/(.*) lib/vendor/symfony/data/web/sf/$1 [L]
RewriteRule ^$ web/ [L]
RewriteRule (.*) web/$1 [L]
</IfModule>
i do like this on the root :
RewriteEngine On
RewriteBase /
RewriteRule (.*) ./web/$1 [L]
And edit web/.htaccess uncommented the 'RewriteBase /' line.
this make all the mysite.com/aaaa/bbbb works like mysite.com/web/aaaa/bbbb
Short answer: no.
Bit longer: you will have to edit the apache config at least to give it permission to access the web/ directory, so even if you symlink your web folder to /var/www, it will not work.
This is quiet similar to my question Symfony on virtual host (document root problem).
This is my .htaccess in the project root directory:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/images/ [OR]
RewriteCond %{REQUEST_URI} ^/js/ [OR]
RewriteCond %{REQUEST_URI} ^/css/
RewriteRule ^(.*)$ /web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteRule ^(.*)$ /web/index.php [QSA,L]
This solved my problem but symfony tries to generate every url (eg. using url_for) from the document root so instead of url like domain.com/my-article it generates domain.com/web/my-article.
I had to slightly modify my PatternRouting class to trim the /web prefix from each url. I think this is not the best solution but it works.
Also if I want to access backend application I have to call always /web/backend.php/ because I don't want to have so many rewrite rules in the .htaccess.
If you want to see my extended PatternRouting class source code I'll paste it here.
Yes, it is possible. Copy everything from web/ up a level to your document root. Edit index.php to reflect the fact that everything it includes is now one level closer to its current directory than it used to be (one less ../). You won't have to edit a single other Symfony file.