Configuring CakePHP .htaccess in Cpanel ~temp/ URL - apache

I'm trying to set up CakePHP 2.x in Cpanel (Hostmonster) while the domain of the site is still pointing to the older server. In order to pull up the site without the domain (for demo), I have to use http://[hosting-IP-address]/~mysite.
This is my default .htaccess file located in the root (the one before app/ folder):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
If I leave it as it is, I get 404 error. When I remove the .htaccess file or leave it blank, the site content loads, but without CSS. The site files are located in /home2/mysite/public_html/ folder. I tried adding RewriteBase with different combinations (~mysite, mysite, mysite/public_html), but no avail.

Try this in htaccess file:-
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Hope it will work!

Related

Getting 404 error when viewing CakePHP 3 app on 1and1

When I attempt to hit my site which is at mydomain.com/subfolder, I get a 404 (from Apache).
/subfolder/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/subfolder/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
To confirm that mod_rewrite works, I added this in the /subfolder/.htaccess file which promptly redirected:
Redirect 301 / http://other-domain-owned.com/
So, .htaccess are live and mod_rewrite works.
On my development environment, I was able to make the site work in the same /subfolder by symply enabling .htaccess files for that folder via a Directory directive.
Some tutorials say to add RewriteBase / but this didn't help.
Instead of RewriteBase, you can also use an absolute path. Additionally, the first two rules can be simplified to one
RewritRule ^(.*)$ /subfolder/webroot/$1 [L]
Similar the second part
RewriteRule ^ /subfolder/webroot/index.php [L]
Finally, Redirect and RewriteRule are from different modules. So, if one of the directives is working, this is no proof for the other one working too.

500 Internal Server Error in subdomain

I'm working on trying to add new web site on subdomain but I'm getting Internal Server Error.
When I remove .htaccess from root folder subdomain site is working but current site brokes down.
.htaccess in root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ app/ [L]
RewriteRule (.*) app/$1 [L]
</IfModule>
I'm trying to figure out how to setup .htaccess and make current site working and site on subdomain.
New website is in Drupal. Current web site is Cakephp
Update:
error_log
RewriteCond: NoCase option for non-regex pattern '-f' is not supported and will be ignored
I fixed adding this in my root .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

.htaccess trouble with cakephp and addon domain

I'm trying to add an addon domain with its own site to my hosting account which already has a cakephp setup.
I was experiencing a 500 error on the addon domain, but I managed to remove this using the solution at: http://expertsoverflow.com/questions/21345626/htaccess-addon-domain-issue-gives-500-error
Now my .htaccess file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^maindomain\.co.uk [NC]
RewriteRule ^(.*)$ app/webroot/$1 [L]
RewriteCond ^seconddomain\.report [NC]
RewriteRule (.*) http://seconddomain.report/$1 [L]
</IfModule>
Now my addon domain works as expected but my main domain isn't correctly forwarding image/file requests to the app/webroot folder so none of the images and css are loading and no pages work past the first index.
For reference the initial cakephp .htaccess file was:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Any help is appreciated.
Edit: my folder structure:
Main domain:
/public_html/
/public_html/app/webroot/
Second domain:
/public_html/seconddomain/
I managed to solve this by changing the directory of the addon domain.
Rather than having the addon domain in /public_html/seconddomain/ it is now /seconddomain/ in root. Then I'm just using the standard .htaccess files for cakephp in the /public_html/ folder.
I know it is very late but i got a solution for it.
Add the rewrite rule in primary .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} seconddomain.report
RewriteRule seconddomain.report/ - [L]
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Cake 2.+ on shared hosting - 404 error

Since 2 days I have been trying to get my cake app working (using German 1&1 hosting). The desired address is: http://www.bzalewski.de/k/front. If you open it, you can see, it's there but without images and css. Also this: http://www.bzalewski.de/k/front/art/discover doesn't work (but it does locally with XAMPP. There is no routing, just ArtController --> public function discover()).
I followed the instructions from this article: http://bakery.cakephp.org/articles/tim_m/2007/09/20/500-errors-with-1and1-hosting-apache-1-x
My three .htaccess look like this:
./.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) k/front/app/webroot/$1 [L]
</IfModule>
./app/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) /k/front/app/webroot/$1 [L]
</IfModule>
.app/webroot/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /k/front/app/webroot/index.php?url=$1 [QSA,L]
</IfModule>
I would appreciate any help to:
make controllers work (art/discover working)
make images and other stuff in the webroot directory work
Just to mention it: my local XAMPP installation works with standard .htaccess files without any problems.
Try adding this line in the root .htaccess (the htaccess in /k/front/ folder) after RewriteEngine On:
RewriteBase /k/front/
Edit : I did not see that you put /k/front/ everywhere in the htaccess
Then add RewriteBase / with you version of the htaccess
OR add RewriteBase /k/front/ with the default htaccess (without /k/front/ in the RewriteRules )

Controlling redirection of CakePHP with .htaccess

I’ve installed cakePHP on Windows7+Apache2.2 and tried blog tutorial.
Now I’ve been confusing redirection control with .htaccess.
I’ve followed instruction of tutorial for setting .htaccess.
htdocs
.htaccess
app
.htaccess
webroot
.htaccess
Eache .htaccess files are below.
[under htdocs]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
[under app]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
[under wabroot]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
But error happens,here is message in error.log
client denied by server configuration: :/Apache2.2/htdocs/app/webroot/.htaccess
What’s wrong ?
This tutorial app uses following URLs.
http://mydomain/posts/index // show index page
http://mydomain/posts/view/3 //show an article selected from index(3 means ID number)
http://mydomain/posts/add //show a page for posting new articl
http://mydomain/posts/edit/3 //show a page for e
http://mydomain/posts/delete/3 //delete an article selected from index
.htaccess control redirection normally when URLs are /index and /view/3.
But if URLs are /add ,/edit/3 and /delete apache doesn’t redirect them to index.php.
Actually operation for articles with add ,edit and delete are processed successfully.
And add,edit and delete use POST method
I guess if its method is POST redirection will be failure.
Your folder structure is not seems good... You have to create a project name under htdocs and copy Cakephp files to that folder. Like-
htdocs
--myapplication
.htaccess
-- app
.htaccess
-- webroot
.htaccess