cakephp installation htaccess issue - php

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.

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 issues with .htaccess file on site5 server

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>

Only directory listing in cakephp setup

I have a Cakephp backup and I want to setup it on my local xampp setup. I backup it from the server in which it is running smoothly. When I want to open using localhost, it displaying the /app/webroot/ directory listing.
I am using windows 7 with xampp. I started mod_rewrite already.
my .htaccess file has
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
DirectoryIndex /front/default.php
</IfModule>
Something is wrong in your document. Your .htaccess should like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try this code:
DirectoryIndex index.php
RewriteEngine on
RewriteRule ^(.*)$ app/webroot/$1 [L]

Friendly URLs cakephp 2.3

I'm new using cakephp, and I'm trying to set Friendly URLs for my site, but I'm having problems.
I've already made all the steps that the cakephp 2.3 Book says, and my apache configuration says that the mod_rewrite is being executed.
And when I enter the main page of cake, it says that the URL rewriting is not configured, and when I want to acces to my web I need to go throught www.mysite.com/index.php/controller/function and of course, i want this: www.mysite.com/controller/function, and if I try this route, it says that is not found in my server (and I have the controller and function created).
This are my .htacces files:
root directory:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
App directory:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Webroot directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I resolved It. in the file /etc/apache2/sites-enabled/000-default the directory was pointing to /var/www and my cakephp directory was in /var/www/html/myapp/cakephp. I changed it and now its working! :)

htaccess with cakephp on justhost account 500 error

I am having an issue with the .htaccess file on a justhost.com account. I recieve constant internal 500 errors and I have tried many different solutions around the web. Here is what my htaccess files look like:
ROOT HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app/ HTACCESS
<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 [QSA,L]
</IfModule>
The issue is that I get this in the error log:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Ive tried setting the RewriteBase to / but it doesnt correct the issue.
You have to use Rewrite base in three .htaccess files. The one in the root directory which contain directories app , lib , plugin and vendor should look like
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
The app / htaccess should look like
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
And finally the app/webroot/htaccess should look like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/webroot
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
If your lib is not in the root folder you will have to also the change the values in core.php to map it to relevant address. For that you can check out the advanced installation in the cook book.
Check your file permission.
Switch off your htacess file and write echo 1;exit; index.php and check weather it shows or not.

Categories