CakePHP issues with .htaccess file on site5 server - php

Building a CakePHP website for a client, it runs perfectly on my local environment, and when being tested on my server. However, when I transferred it to the client's site5 server it returned nothing but 404 errors.
After some modifications to the .htaccess files I was able to get the default landing page working fine:
http://174.120.222.98/~sty/
The issue I have, is that only the default landing page can be found. All of the sub-pages are still returning 404 errors (example: "NEW STUDENTS" Green-background link in NavBar).
I've changed the root/.htaccess file to:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~sty
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
without RewriteBase /~sty The default landing page is a 404.
I've changed root/app/.htaccess file to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Without this change, none of the files in webroot loaded (images/styles/js).
Those two files alone seem to be all I need for the default page, I can even remove the root/app/.htaccess file and the landing page looks great. So I'm assuming the app file is the one that will govern my sub-pages. Nothing I've done to it seems to work, it is currently set to:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~sty
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
I've tried to RewriteBase with \, \~sty, \~sty\app and without the line so far none of my changes seem to work.
Help me StackOverflow, you're my only hope.

mod_rewrite is not enabled on your server so you have to handle this with .htaccess file in your root directory
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
and another .htaccess in your app folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
and another one in your webroot folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Related

Setup cakephp in subfolder on AWS

I had shifted my cakephp website to a subfolder on AWS ubuntu machine. Site is working but CSS, Images and JS are not loading.
I am getting 404 not found error.
Not Found
The requested URL /demo/css/mscrollar/jquery.mCustomScrollbar.min.css was not found on this server.
Urls are working only with index.php.
Here is the htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /demo
RewriteRule ^media/(.*) http://%{HTTP_HOST}/files/timthumb.php?src=http://%{HTTP_HOST}/app/webroot/files/$1 [L,R=301]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Please help
You need to create two htaccess files. One in the webroot and one in the root path.
The one in the root (./.htaccess) should look like this (replace YOUR_PATH):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /YOUR_PATH
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
The one in the webroot folder (./app/webroot/.htaccess) should look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Cakephp css,images and subpages are not loading

My website(http://www.mytripkerala.com/) which is built in cakephp works well in old server.When i changed it to my new server the homepage is loading without style and images.And all subpage links showing 404 error.My htaccess files are
htaccess inside webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
htaccess inside app folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
htaccess outside app folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Please help me to solve the problem..

.htaccess rewrite rule exception

I have a small question.
I have build a system and it is using a .htaccess to direct the traffic to the correct locations.
Now I have the following .htaccess data
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
///### (does not work.. this is a problem) RewriteRule (.*) app/template/ !page [L]
</IfModule>
The problem is actually that when I want to show a .css file located in /app/templates it also redirects to /core/
I tried to make an exception. However that does not really seem to work at my method.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
RewriteRule (.*) app/template/ !page [L]
</IfModule>
This .htaccess gives a 500 error.
Could anyone tell me what I am doing wrong? And how I can make the exception work for the template directory?
TIAD!!
You should use:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) core/$1 [L]
</IfModule>

cakephp installation htaccess issue

I'm trying to install CakePHP in www.domain.com/demo/realestate I changed .htaccess in root, app,webroot with ref from cakebook, S.O. and other websites. Most of them produced either 500 error or shown a blank page or 404 error.
My .htaccess code in each of those files are:
--in root--
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /demo/realestate
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
--in app--
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
--in webroot--
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I also tried to delete all .htaccess and write Configure::write('App.baseUrl', env('SCRIPT_NAME')); in app/config/core.php as per a suggestion in documentation but then it started taking demo as controller name and realestate as function name.
I request you to guide me to set it up!
There is no need to change in htaccess if you want to install cakephp in www.domain.com/demo/realestate. Just copy all cakephp files and folders in realestate folder with default htaccess and it'll work.

cake php gives me error when setting up on development server

First of all, I want to describe that I have researched a lot on this question so thats why I am asking so please dont downvote. I have implemented lot of solutions.
I am using cake2.0. I have uploaded a website on development server the link is http://dev.infideaco.com/eventmanager/ . But I am getting the not found error. I have resolved it by changing the .htaccess files but then the css,js and images are still not available.
I have .htaccess files which are provided by default installation. I am setting it up in development server
/var/www/dev.infideaco.com/eventmanager
The website is running fine on other servers.
You can check here:
http://swirlsyogurtbar.com/js/
These are the htaccess files:
root file:<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule sss (.*) app/webroot/$1 [L]
</IfModule>
in app:<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
app/webroot/.htaccess:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Please provide me the solution. Lot of thanks in advance
I would first check if server supports mod_rewrite. Also check this thread if you haven't already: cakePHP - 404- page not found error, when deploying on a different machine
root file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
in app:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
app/webroot/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Categories