Apache 2 /httpd vhost dynamic documentroot - apache2

I have an app in folder /var/www/test
Also there is an "sub-app" in folder /var/www/test/subapp (There is another index.php inside
If user will type test.com the index.php of test should trigger but when user type test.com/triggersubapp the index,php from /var/www/test/subapp shall run.
I failed to create correct statements and RewriteRules and I haven't got much time left. So have any one of You know how to do this easiest way or maybe have a correct definition?
I would greatly appreciate it !!!
EDIT
The main index.php and .htaccess are in /var/www/test/public/. :(

Put this in your .htaccess in root directory:
RewriteEngine On
RewriteRule ^triggersubapp/?$ subapp/index.php
This will rewrite triggersubapp to subapp/index.php which means if user enters test.com/triggersubapp he/she will see result for test.com/subapp/index.php

Related

Joomla 3.x Multilanguages RewriteRule

I have an issue. I set up my joomla 3.3.x with multilanguages.
URL how it appears in the browser:
www.example.com/%LANG%/folder1/module1/images/img.png
%LANG% stands for de, en, ...
And now the actually path where my image is(this is just an example, images/files could be anywhere):
www.example.com/folder1/module1/images/img.png
I thought about a rewrite rule which should get this work.

Change root without change application with CakePHP?

This question is similar to this other one, but I am using full-URL, no mod_rewrite, see cakephp WITHOUT mod_rewrite or this "sibling question".
I have a CakePHP folder that works well, at /var/www/mycake (localhost/mycake). Now I need change to /var/www/test/mycake (localhost/test/mycake)... HOW TO DO THIS CHANGE with minimal PHP code changes?
I add a controller as Cake message recomended:
TestMyCakeController.php ... nothing
TestController.php OK (!), but other error arrises
Cake defines its ROOT directory in the root index.php file. If you look inside you'll see the following lines:
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'mycake');
define('WWW_ROOT', ROOT . '/' . 'test' . '/'. WEBROOT_DIR . '/');
You can easily move a CakePHP application to another directory under your web root. The top level index.php contains the line:
define('ROOT', dirname(__FILE__));
This will set the root directory to the current location of the main index.

Apache vhost_alias

I have a question about vhost_alias
I got it working, it does the following job:
vhost.subdomain.domain.com -> sends to /var/www/vhost
using virtualdocumentroot and %1
But I don't like that I can access the same content also like this
vhost.vhost.subdomain.domain.com
since I have ServerAlias to *.subdomain.domain.com
How can I force that only vhost.subdomain.domain.com works?
The aim is to have many vhosts like this, for exmaple vhost1, vhost2, etc.
Thanks,
David
One solution you could try is to add a fixed subdomain in your ServerAlias, before your actual dynamic subdomain:
Example:
ServerAlias www.*.subdomain.domain.com
This will ensure that
vhost.vhost.subdomain.domain.com
does not redirect, however, you will be forced to always add www. before your name.

Symfony does not detect relative url root

In symfony 1.4 in settings.yml we are using the option:
env:
request:
param:
relative_url_root: /name-of-app
to specify which relative_url_root an app uses. So every app runs under a different relative_url_root.
The problem is that symfony 1.4 routing does not detect this relative url root. So for example if we have the following route:
route_name:
url: /some-module/some-action
param: { module: somemodule, action: someaction }
And we try to access http://myproject.local/name-of-app/some-module/some-action symfony tries to search for a route name which matches name-of-app/some-module/some-action instead of /some-module/some-action.
Also symfony now tries link to images using this relative_url_root, therefore images are not found anymore. Because images are only reachable via http://project.local/img/.. instead of http://project.local/name-of-app/img
What is the best way to solve this?
Should I remove a '/' somewhere?
Should I use RewriteBase somehow in htaccess?
Should I strip 'name-of-app' in the REQUEST_URI using htaccess?
Prefix every routing url with name-of-app/?
Should I in someway tell apache that /name-of-app is some kind of path or prefix? Note that in our production environment we are not able to create virtual hosts so we have to solve this using .htaccess or symfony itself.
A very different solution.
I'm not sure if the relative_url_root is what you're really after. As the documentation states:
relative_url_root
The relative_url_root option defines the part of the URL before the front controller. Most of the time, this is automatically detected by the framework and does not need to be changed.
So it is part of the URL before index.php or frontend_dev.php, etc.
What you could do, in my opinion, is to write your own Routing class which will extend the sfPatternRouting and have it remove the prefix part of your URLs before trying to match any route. Then use this class for routing in factories.yml.
EDIT: I somehow missed the fact that you operate between different applications.
In general the relative_url_root is definitely not a good idea to separate calls to different apps. The best way, in my opinion, would be to use separate front controllers and Virtual Hosts to have different subdomains. Unfortunately you say you cannot go for this option.
You could then go for either of the solutions:
Fiddle with .htaccess and have it redirect your calls to a proper front controller: myurl.com/path-to-app1/something will call app1.php/something and myurl.com/path-to-app2/something will call app2.php/something.
Change the index.php file. Have it catch the first part of URL (path-to-app/) and based on it's value load the configuration for the proper app (e.g. $configuration = ProjectConfiguration::getApplicationConfiguration('app2', 'prod', false);)
You would then have to change your routes to take into consideration that there is this first part of URL (e.g. have all your routes start with a :path-to-action variable which will be passed to functions generating URLs), or use a parameter defined in config:
.
In apps/app1/config/app.yml
path_to_app: app1
In apps/app1/config/routing.yml
route1:
url: <?php echo sfConfig::get('app_path_to_app') ?>/something
...
Fix for the routing:
I changed my .htaccess as follows.
RewriteCond %{HTTP_HOST} myproject.local
RewriteCond %{THE_REQUEST} /name-of-app* [NC]
RewriteRule ^(.*)$ dispatcher.php/$1 [QSA,L]
By using this rewrite rule symfony seems to recognize that /name-of-app is a prefix in the routing and somehow matches this on the relative_url_root. Now when I var_dump the sfRoute object in the controller I get the following.
object(sfRoute)[33]
protected 'isBound' => boolean true
protected 'context' =>
array (size=7)
'path_info' => string 'some-module/some-action' (length=10)
'prefix' => string '/name-of-appp' (length=8)
'method' => string 'GET' (length=3)
'format' => null
'host' => string 'myproject.local' (length=20)
'is_secure' => boolean true
'request_uri' => string 'https://myproject.local/name-of-app/some-module/some-action' (length=47)
Note that I did not change the routing rules as Michal suggested. Also I believe my approach with the relative_url_root is not really that strange as Symfony understands it.
Fix for direct file access:
In order to redirect a request like https://myproject.local/name-of-app/some/path/to/a/file.ext to https://myproject.local/some/path/to/a/file.ext I used the following directives.
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} ^/name-of-app
RewriteRule ^name-of-app/(.*)$ https://myproject.local/$1 [L]

CakePHP 2.1 new install Missing Controller Error

I am completely new to CakePHP and installed 2.1. I am getting this error:
Missing Controller
Error: Index.phpController could not be found.
Error: Create the class Index.phpController below in file: app\Controller\Index.phpController.php
<?php
class Index.phpController extends AppController {
}
Notice: If you want to customize this error message, create app\View\Errors\missing_controller.ctp
Stack Trace
APP\webroot\index.php line 96 → Dispatcher->dispatch(CakeRequest, CakeResponse)
ROOT\index.php line 40 → require(string)
I followed their guide at http://book.cakephp.org/2.0/en/installation/advanced-installation.html and tried everything it stated:
I enabled mod_rewrites (they were already enabled from something else)
I have all the .htaccess files in the directories
I have cake installed under my document root so I access it at localhost/cakephp/index.php
I do not know where to proceed from here. Thanks for any help you can give me.
Update: I just re-read your question and realized you're loading http://localhost/cakephp/index.php. Don't do that. Since you appended "index.php", it is trying to load a controller called "index.php" and the action "index" for that controller. Resulting mapped path to the "index.php controller" is app\Controller\Index.phpController.php.
Since you have the rewrites enabled, browse to http://localhost/cakephp without appending any filename.
Original answer:
Assuming you're using Apache, double-check the .htaccess in your /app/webroot directory. It should include the following:
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Based on your error, it doesn't look like it's properly appending the path after your index.php file.
If you are using cakephp 2.0 or greater than rename the controller file name as the class name.
ie TaskController.php
class TasksController extends AppController {
--Your code inside class
}
I hope this will help you
the easiest solution is to stick to the "live environment" as close as possible.
this means using vhosts to use a "domain" and correctly root down to your webroot dir:
http://www.dereuromark.de/2011/05/29/working-with-domains-locally/
this leaves almost no room for error and also helps with other potential problems like "absolutely linked asset files" etc

Resources