Joomla 3.x Multilanguages RewriteRule - apache2

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.

Related

Apache 2 /httpd vhost dynamic documentroot

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

Compression not working on web pages

I have a apache/php server and am trying to optimize my site by enabling compression.
I have checked out numerous articles and they say you need to create a .htaccess file. I've tried that with:
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
I then tried http://www.feedthebot.com/tools/gzip/ and it reports my web site is not using compression.
What am I missing?
This is from phpinfo:
Loaded Modules core mod_access_compat mod_so http_core prefork mod_unixd mod_systemd mod_actions mod_alias mod_auth_basic mod_authn_file mod_authz_host mod_authz_groupfile mod_authz_user mod_autoindex mod_cgi mod_dir mod_env mod_expires mod_include mod_log_config mod_mime mod_negotiation mod_setenvif mod_ssl mod_userdir mod_php5 mod_reqtimeout mod_authn_core mod_authz_core
Followed this and it works 100%
http://www.garron.me/en/linux/enable-gzip-mod_deflate-compression-apache.html

Is it possible to change image folder in cakephp 2.4

I have read many docs, but failed to solve the problem:
Images in my existing project stored in $_SERVER['DOCUMENT_ROOT'].'/media/'
I want, but can't change in cakephp 2.4 default image folder from $_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/' to any I desire.
lib/Cake/bootstrap.php contains constants:
/**
* Path to the public images directory.
*/
if (!defined('IMAGES')) {
define('IMAGES', WWW_ROOT . 'img' . DS);
}
/**
* Web path to the public images directory.
*/
if (!defined('IMAGES_URL')) {
define('IMAGES_URL', 'img/');
}
and
Configure::write('App.imageBaseUrl', IMAGES_URL);
I tried to change:
IMAGES to $_SERVER['DOCUMENT_ROOT'].'/media/'
IMAGES_URL to /
And it doesn't work at all. All image files still points to $_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/' I see it when try to render image in view:
echo $this->Html->image('/img/ride_scheme/chema.jpg', array( 'width' => 300 ));
If I created in app/webroot/img/ride_scheme image file chema.jpg it rendered, but I changed the folder in IMAGES constant in lib/Cake/bootstrap.php !!!
In documentation I see:
Constants IMAGES_URL, JS_URL, CSS_URL have been deprecated and
replaced with config vari- ables App.imageBaseUrl, App.jsBaseUrl,
App.cssBaseUrl respectively.
Constants IMAGES, JS, CSS have been deprecated.
I gues that is the problem.
Please, show me how to change image folder
According to your description, I reckon IMAGES_URL should be media/ and not just /.
Alternatively, you could add a RewriteRule to your .htaccess (in the project root) to rewrite everything to the media folder (assuming you have an Apache web server with the Rewrite module enabled):
RewriteRule ^app/webroot/img/(.*) /media/$1
Or you could create a symbolic link that links the img/ folder to your media folder (assuming you're on Linux hosting and you have ssh/shell access to your server):
cd app/webroot
rm -rf img/
ln -s ../../media img

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