cakephp .htaccess configuration on godaddy with subdomain - cakephp

I have one domain on godaddy (www.mydomain.com). I have placed my cakephp application on this domain. It is working fine for me.
But i have created a subdomain blog.mydomain.com for this godaddy has created a directory named blog inside the www.mydomain.com now how can i redirect the request coming for blog.mydomain.com to the blog/ folder.
I am trying this,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.mydomain.com$
RewriteRule ^(.*)$ blog/$1 [L]
RewriteCond %{HTTP_HOST} ^mydomain.com/$
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
It works for single Rewrite condition like,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.mydomain.com$
RewriteRule ^(.*)$ blog/$1 [L]
But when i add another rewrite condition for my cake app it shows 500 Internal server error for blog.mydomain.com
Please help me out .............

Put the blog folder in webroot (under your cake directory) and it should work just fine. Or did you need to do something else more fancy?

Try this: http://digitalmemo.neobie.net/2011/04/19/cakephp-bypassing-for-subdomain/
It use to make all the subdomains to be working correctly instead of defining each of the subdomain.

Related

Handling URL routing with Apache and React Router

I have a pair of apps which will be running on a shared Apache host. The apps are housed in a common directory on the server. Each application is housed within a "build" directory within its main directory. The client directory should be the default display, while admin should display at example.com/app/admin. And, to further complicate matters, admin uses React Router for its internal routing.
Here's a visual representation of the goal:
admin
|- build
|- index.html (example.com/app/admin, example.com/app/admin/page1, etc.)
client
|- build
|- index.html (example.com/app)
.htaccess
So I need to load the target pages while also enabling React Router to handle the routing for admin. I've tried about every combination of RewriteCond and RewriteRule I can think of in the .htaccess, but no luck so far. I feel like I'm getting closer with the rules below, but I'm still not quite there.
// .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/admin/build
RewriteRule ^admin$ admin/build [L]
RewriteCond %{REQUEST_URI} !^(/client/build|/admin)
RewriteRule ^(.*)$ client/build [L]
</IfModule>
This shows /build in the address bar, and any request to /admin/(.*) fails to redirect the .css and .js file requests to the build folder (so it is instead looking for /admin/static/css/ instead of /admin/build/static/css), although they load successfully on requests to /admin.
EDIT: Changed "App1" to "client" and "App2" to "admin"; masking those serves no purpose, and the fact that the directory shares a name with the page might somehow be relevant.
Finally got this sorted out. Final rewrite below.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} -f
RewriteRule .* - [L]
RewriteCond %{REQUEST_URI} !^/app/admin [OR]
RewriteCond %{REQUEST_URI} ^/app/admin/build
RewriteRule .* - [S=2]
RewriteRule admin/\w*/?$ admin/build/index.html [L]
RewriteRule admin/(.+)$ admin/build/$1 [L]
RewriteCond %{REQUEST_URI} !^(?:/app/client/build|/app/admin/build)
RewriteRule ^(.*)$ client/build/$1 [L]
</IfModule>

CakePHP project redirecting from localhost to live website

I need to make some changes on an existing CakePHP project, but I can't run it on localhost because every time I try to access http://localhost:8080/{name-of-project}/ it redirects me to http://www.{name-of-project}.com.
Any help would be appreciated.
I also encountered this one when Im still using cakephp2 and still duable using cakephp3
from live .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTPS}s ^on(s)|off
RewriteRule ^(.*)$ http%1://www.mydomain.com/$1 [R=301,QSA,L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
I change it to this one
.htaccess local
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Most likely in your .htaccess file there is a non-www to www redirect installed.
As Adam notes, it may be useful to clear your browser cache when working with redirects. A cached redirect would no longer hit your server configuration so any changes you do will not be visible.

.htaccess and CakePHP: Creating a directory for use with Angular-UI router

I've got an AngularJS app running on top of CakePHP 2.6. I'd like to enable html5mode in Angular so I don't have to include a # in URLs, but doing so requires configuring some .htaccess files so that all requests hit index.html.
Not all of my web app is Angular yet, so I can't just redirect everything to index.html- instead, I'd like to set things up so that all requests to a certain subdirectory (and its subdirectories) redirect to that subdirectory's index.html.
CakePHP has a folder structure like this:
/ // Server web root directory: index.php, etc
----/app // The directory containing the actual Cake app
----/webroot // Web assets used by the Cake app
----/myapp // Where I'd like to store the index.html for my Angular app
I'd like to get this set up so that any requests to /myapp or its subdirectories get automatically redirected to /app/webroot/index.html. Does anyone have any ideas about how to go about this?
My current .htaccess files:
/:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/app:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/app/webroot:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(app/webroot/)?(img|css|js|eot)/(.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I would just create a controller in CakePHP to handle all requests for myapp and render the static HTML as a view with a custom layout (if required).
Performance will not be an issue because the route for CakePHP will only be executed once. After that the AngularJS app is running and will take over all HTML5 routing locally in the browser.
While you can achieve what you want in .htaccess it limits you to running the CakePHP application on Apache. If you want to scale later to IIS or Nginx you'll have to recreate these rewrite rules.

.htaccess fine on localhost, 500 internal server error on webserver

I'm trying to redirect show files in folder/dist when accessing folder/ in a webapp using .htaccess.
This works as desired on localhost (xampp apache) but when pushed to the server (AWS Elastic Beanstalk Apache) I get a error code 500 Internal Server Error.
I've created the webapp using the Yeoman Angular generator and it's running the webapp on an Apache server. The project is in a subfolder of the whole site (http://url.com/pages/webapp). Grunt creates the application in the dist folder and I this content is what I want the visitor to see when accessing the root of the webapp.
Basically I want to redirect/rewrite http://url.com/pages/webapp/ to http://url.com/pages/webapp/dist/
Im trying to accomplish this with a .htaccess that looks like this:
RewriteEngine On
RewriteRule ^$ dist/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^dist/
RewriteRule ^(.*)$ dist/$1
The exact same htaccess-content is used in other projects on the same server and they work fine. Only projects created with this generator has this issue.
Is the problem in my htacceess-file, other part of webapp or Elastic Beanstalk...?
I have tried adding AllowOverride All (root directory) and LoadModule rewrite_module modules/mod_rewrite.so to /etc/httpd/conf/httpd.conf but it didn't work.
I also didn't find anything interesting in error_log
I realize the problem is probably hard to solve with the information provided but I am hoping someone else has had a similar issue.
Thanks
Try this code in root .htaccess:
RewriteEngine On
RewriteRule ^$ dist/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/dist/ [NC]
RewriteRule ^(.*)$ dist/$1 [L]
Note leading / before dist in RewriteCond.

Installing CakePHP 2.4.7 on Windows

I am facing issue in my first intallation of CakePHP.
I am working on Windows OS and using WAMP. I am able to point my browser to localhost -> phpcake to open my installation of CakePHP.
However I get an error as below:
Missing Controller
Error: PhpcakeController could not be found.
Following are the steps which I followed for installing CakePHP:
Unzipped CakePHP, version 2.4.7 and loaded that in my WAMP
Created database using phpMyAdmin
Updated the app\Config\database.php file with login, password and databasename
The contents of the .htaccess files of cake is as below:
phpcake/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
phpcake/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
phpcake/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase D:/Vivek/phpcake/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(app/webroot/)?(img|css|js)/(.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
The mod_rewrite is disabled on my Apache. If I enable it, then I get 404 error on launching CakePHP install.
Could you guide me as to which step am I missing?
Finally i got it working. This is what i was doing (wrong).
In my WAMP i created an alias directory. Apache -> Alias -> Add an Alias Directory. In this alias i pointed to the location of my CakePHP unzipped folder. I updated the App/Config/Database.php to point to created MySQL database. However on selecting mod_rewrite module in Apache i was getting 404/403 errors. And without mod_rewrite i was getting missing controller error.
Missing Controller
Error: PhpcakeController could not be found.
I tried fresh installations 3 times with same results.
My understanding is that the mod_rewrite, the instructions in Alias file and .htaccess files were creating this trouble.
So this is what i did (Worked):
I copied my CakePHP into WAMP's www directory. That's it, it did the trick. I went through various articles about .htaccess, and mod_rewrite. Frankly speaking it is complex for me.

Resources