symfony on virtual host document root problem - symfony1

Im trying to deploy symfony on virtual host.
mod_rewrite converts /web URLs to domain root URLs (domain.com/image.gif is turning internaly into domain.com/web/image.gif).
But thanks to web is executed internaly from /web dir, Symfony is still thinking it has document root there and prefixes any url_for() URLs with /web.
So when i have route:
show_books:
url: /books
..and iam asking for:
url_for('#route_name')
Symfony is generating:
/web/books
I cant change hosting behaviour, i need to have web request pointed into symfony root path and internaly redirected into /web dir and i want to symfony ignore the point it is executed from |hostname-document-root|/web

I found the insert of this code into top of my front controller (/web/index.php) as good solution:
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'] = '/index.php';

Related

Rails 3 redirect a public file to an external path

Using Rails 3 and Ruby 1.9.3, I'm trying to redirect a file in my public folder to an external URL.
This is because this file is going to be managed by another party.
I'm unsure how to accomplish this.
But I need for a file like this:
mysite.com/publicfile.html
to redirect to:
someoneelsessite.com/publicfile.html
Add a route:
get 'publicfile.html', to: redirect('https://someonelsesste.com/publicfile.html')
https://guides.rubyonrails.org/routing.html#redirection
Make sure you DON'T have that publicfile.html file on your public folder, or it will be served before reaching the router.

Grails change web-app static directory

I'm running an application through grails 2.2.4. As it stands, grails handles all requests from the base of the "web-app/" directory. Unfortunately, all the URI references in my web-application are of the type "app/images", "app/styles", "app/scripts", etc. This means that any call to "/images" is hitting "web-app/images", instead of the true "web-app/app/images". Is there a simple way to prefix on an additional "/app/" in front of all calls?
file structure:
/web-app
/app
/images
/styles
/scripts
If you are using Resources plugin (which I think you would be), then have a look at the configuration section.
You would need the below settings in Config.groovy:
grails.resources.work.dir = '/app/'
//if a prefix is required other than 'static'
grails.resources.uri.prefix = '/content/'

Deploy ZF2 site to shared host

When you deploy a Zend Framework website to a shared host, you usually cannot change the DocumentRoot to point at the public/ folder of the website. As a result the URL to the website is now http://www.example.com/public/. This doesn't look very professional, so I'd like to remove it. Up to now I have used ZF1 and Rob Allen kindly provides a method for doing this on his blog http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/ . I have tried to modify this for ZF2. He proposes placing an index.php file in the root with the line:
include 'public/index.php';
After doing this, http://www.example.com opens the index page OK but the CSS links are broken. Rob adds a controller plugin to reset the baseUrl to /public to deal with public facing CSS and image files etc. To do this in ZF2 I found an item from Matthew Weier O' Phinney http://zend-framework-community.634137.n4.nabble.com/Setting-the-base-url-in-ZF2-MVC-td3946284.html where he describes how to set the baseUrl. Based on his code I added this to modules/Application/Module.php
class Module {
public function onBootstrap(MvcEvent $e) {
$config = $e->getApplication()->getServiceManager()->get('config');
$router = $e->getApplication()->getServiceManager()->get('router');
$router->setBaseUrl($config['base_url']);
}
}
The base_url key is set in modules/Application/configs/module.config.php:
'base_url' => '/public'
I was able to dump the router object and confirm that the base_url was being set correctly at this stage. Unfortunately, now http://www.example.com no longer opens the index page and gives a 404 routing error.
Is anyone able to tell me what I am doing wrong or point me in the right direction for running a ZF2 site in a shared hosted environment?
Are you using the skeleton app?
that seems a little over the top, surely it's lot simpler than that.
move everything from public to the root
change index.php
<?php
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
//chdir(dirname(__DIR__));
chdir(__DIR__);
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
Simples.
If you are running an application like this you may want to block direct access to some of the Zend Framework folders using htaccess etc

Need to have either example.com/username or username.example.com, but how?

I'm almost finished developing my large project, however I would love it if I could make it so instead of having the users profile pages at: http://example.com/profile/username/USERNAME
(i'm currently using .htaccess to rewrite the GET data into forward slashes and profile(.php) being read as just 'profile' profile.php also parses the url correctly to retrieve the GET data)
But it would be some much better if I could do it so that it's like http://www.example.com/USERNAME (preferred) or http://www.USERNAME.example.com
Any ideas or resources?
Thanks,
Stefan
In your .htaccess in the root, add
RewriteRule ^/([^/]+)/? /profile/username/$1
This matches paths that don't include a slash (so no directories in the path) and suffixes the path to /profile/username/. The path can include an optional final slash.
(+1 for the comment about namespaces - it's a little dangrous having usernames in the root of your site. I've tried to limit the impact of this by only giving out the namespace comprising a single directory. Paths with multiple directories will be handled as normal.)

Grails application root path

Is there a variable where I can find out the root directory of my Grails application?
for example, I have a folder named chart under \%root%\web-app\images\ where I put my charts in. Once I deploy my Grails application on Jetty, I will get FileNotFoundException because the root path becomes /srv/www/vhosts/domain-name/jetty-version/
I would like to know if there is a variable that returns the root path (like /srv/www/vhosts/domain-name/jetty-version/webapps/myapp), and there should be because CSS uses relative path just fine.
solved.
request.getSession().getServletContext().getRealPath("/")
this actually gives me the path to where my application puts the images, css, WEB-INF, etc. folders.
System.properties['base.dir']
I know it is an old question, but this could work if you are not in an http request:
ServletContextHolder.servletContext.getRealPath('/')
If you want to establish this is GSPs try this:
${createLink(uri: '/')}

Resources