I have a problem with my site. After upgrading to mySQL 5.6, then the host povider did a recompilation of Apache and PHP. apparently they also upgraded the WHM cPanel.
as for now my site can display properly, but when tried to login, it can't find the specific page requested.
The error Message:
The requested URL /main/cek_login was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
error messages from cPanel:
[Mon Dec 22 10:10:58 2014] [error] File does not exist: /home/xxx/public_html/main
[Mon Dec 22 10:10:56 2014] [error] File does not exist: /home/xxx/public_html/404.shtml
My analyses so far:
CI version : 2.2
PHP Version : 5.4.3.5
mySQL version : 5.6.21
cPanel Version 11.46.1 (build 4)
main -> is actually a file called main.php
cek_login -> is a function inside main.php that run verification against record in user table.
the folder structure as follows.
/home
/application
/controllers
/main
/view
/login_view
/system
/assets
/cgi-bin
The code as follows
<div class="loginForm">
<?=($_GET[ 'error'])? "<div class='alert'>$_GET[error]</div>": ""?>
<form class="form-horizontal" action="<?php echo base_url().'main/cek_login'; ?>" method="POST">
config.php inside application folder
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; -> tried AUTO before, but useless. Previously was AUTO
.htaccess in root folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
.htaccess in another folder
deny from all
routes.php
$route['default_controller'] = "main";
$route['404_override'] = 'not_found';
I tried to see config files as well and tried a lot of tricks before posting this.
my suspicion is on the base_url function or the routing mechanism. I am not sure.
I am NEW to Code Igniter or PHP, also in Server Administration. my strength lies in Database.
Please help on narrowing the root problem.
best regards,
Ridwan
That error can happen for many reason. here is some
1.make sure you have main.php under controllers folder and inside main.php you should have a class Main which extends CI_Controller like this
class Main extends CI_Controller
2.make sure your .htaccess working.If your previous step is ok then try to hit this link
your_site_url/index.php/main/cek_login//make sure cek_login function exists inside the controller
If this link works you may have .htaccess problem
3.your cpanel error tells that your .htaccess not working.
check your server if it has main .htaccess which is redirecting your site if file not found.If so then your sub .htaccess will not work.
I think this is the main reason that produce your error.
Please check your config.php
$config['base_url']
then check 'routes.php', add the line below
$route['main/(:any)'] = 'main/index';
Then, add your login check in your controller file.
// Login check
$exception_uris = array(
'main/cek_login',
'main/cek_logout'
);
if (in_array(uri_string(), $exception_uris) == FALSE) {
if ($this->user_m->loggedin() == FALSE) {
redirect('main/cek_login');
}
}
Just upload a test file and check document root of your server directory.
1.Create a file info.php
2. Write code
<?php
phpinfo();
3.Open any broswer and type http://www.yourdomain.com/info.php
If it works fine, find document roon in listed information of info.php page
If this http://www.yourdomain.com/info.php not works, contact your server support team to fix it. Basically problem with server configuration, not with Codeigniter files.
Related
I'm trying the second way to run PHP code in HTMl file using a rule in .htaccess file as described by the link https://stackoverflow.com/a/6237056/3208225
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
But when I try opening my page e.g. test.html I receive
Not Found
The requested URL /test.html was not found on this server.
Why and how to resolve?
UPDATED (from comments)
I try both on localhost and on my shared hosting. htaccess and html files are in document root. BTW, the homepage (index.html) also returns Not found. In local machine the path is D:/Server/vhosts/another. And without this htaccess such virtual host works just fine. So there is no issue with its configuration.
With your shown samples please try following .htaccess rules file. Make sure your htaccess is present along with your php files only. Also clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^(.*)\.html/?$ $1.php [NC,L]
Fix added by OP: Please note such rule is not execution of PHP code inside of HTML file, but just a redirecting from HTML file to PHP file, so the second file also must exist
I'm trying to make a RewriteRule in .htaccess so that when users visit http://domain.com/pages/1 they actually get a page rendered by Slim framework accessible at http://domain.com/api/v1/pages/1.
The folder structure is as follows:
/api
-index.php <-- This is a Slim index file
-.htaccess <-- This is a Slim .htaccess (unmodified)
/components
-page.php <-- This is a page template that I use for rendering in Slim
index.php <-- This is a homepage
.htaccess <-- This is my wwwroot .htaccess
My page.php template looks like this:
<?php
?>
echo 'This is a page'
Here's the Slim part (for the sake of simplicity it doesn't yet pass the $id' variable to the template):
$app->group('/v1', function () use ($app) {
$app->get('/pages/:id', function ($id) use ($app) {
$app->render('../../components/page.php');
});
});
The rewrite rule in .htaccess under wwwroot is:
RewriteEngine On
RewriteRule ^pages/([0-9]*)?$ api/v1/pages/$1 [L]
There are two weird things that bother me:
In this configuration accessing the page at http://domain.com/api/v1/pages/1 works, but it doesn't work at http://domain.com/pages/1
When I try to access http://domain.com/pages/1 I get a 404 error, which is generated by Slim, rather than apache.
My question is as follows:
What is the correct/proper .htaccess rewrite rule to rewrite an URL for a page rendered by Slim in the above mentioned scenario?
This is due to improper rewrite pattern.
Try
RewriteEngine On
RewriteRule ^pages/([0-9]*)?$ api/v1/pages/$1
I wrote a code to redirect people who ask for foo.html to the page bar.html instead.
my .htaccess file is as below
RewriteEngine on
RewriteRule ^foo.html$ bar.html
It works on localhost.But gets the following error when runs in web server.
HTTP Error 404.0 - Not Found The resource you are looking for has been
removed, had its name changed, or is temporarily unavailable.
I have a domain like example.com where root directory is web.
I have created a subdomain happy.example.com where directory is outside web folder called happy and connected it to happy.example.com.
My webpage tree looks like
happy
web/images
So all my images for root directory are stored in (web/images)
example.com/images
So a full path to an image can be
example.com/images/me.png
Now i have created a sudbdomain which i call:
happy.example.com
What i would like to do is if i type
happy.example.com/images/me.png
then i should be able to see the picture.
So somehow i need to link all images folder to a subdomain from root directory in web.
I hope you guys got my question.
I guess i shoud have an htaccess file with all funny stuff in happy folder?
Cheerz
Since the two document roots of your two domains aren't connect to each other (one inside the other, or the same), you'll need to either redirect or proxy, or, use a script.
To redirect is easiest, but it'll change the URL in the browser's location bar:
Redirect 301 /images http://example.com/images
or using mod_rewrite:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,R=301]
To proxy, you need to have mod_proxy loaded, which isn't always the case if you're using a webhost or hosting service. But you can use the P flag in mod_rewrite to do this:
RewriteEngine On
RewriteRule ^images/(.*)$ http://example.com/images/$1 [L,P]
The last option is to route all image request to a script, like a php script or something. And the script itself returns the image:
RewriteEngine On
RewriteRule ^images/(.*)$ /load_image.php?image=$1 [L]
then you'd have something like:
<?php
header("Content-type: image/jpeg");
readfile('../web/images/' . $_GET['image']);
?>
Obviously, you'd need to check the extension and return the correct content type depending on the image type.
I am having a problem loading a javascript or css or any other file from inside the application/modules directory.
I am using MAMP and CodeIgniter with HMVC and trying to have a js and css folders inside a module folder. Then when I am calling the controller methods I am also loading the asset files.
I have other sites that are working in that way. The structures are the same and the CodeIgniter versions are the same. Basically I have copied the previous website and started from there.
But it always returns 403 forbidden.
What I did but still nothing changes:
the whole site directory is writable and readable.
I can create and read new files from PHP to that dir
I have htaccess file which I tried to remove or change
Reinstalled MAMP
Tried to open a simple html file
The MAMP user and group has full access to the dir
I tried to run the website on another server
The apache log says "[Tue May 22 17:24:30 2012] [error] [client 127.0.0.1] client denied by server configuration"
Here is the .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
At the same time everything is fine with the other site.
I have spent many hours so far and I am stuck.
Any thoughts or suggestions are appreciated.
Thanks,
CodeIgniter comes with a .htaccess in the /application directory which contains
Deny from all
You'll need to remove this file or change it's ruleset to access js/css files etc from anywhere inside application/*
It is however largely inadvisable to allow access entirely to the application, it's perhaps best to modify this .htaccess file to allow access to application/modules/*/css|js/