BaseURL in symfony 2 - symfony

I have an application in Symfony 2. It is deployed on IIS server.
The problem is, I need to get it work on multiple URLs:
www.somedomain.com/myapp/app.php - for production
www.somedomain.com/myappdev/app.php - for testing
myapp.localhost/app.php - for development
How can I do that? I need to correctly generate URL for resources(js, css files). Also after deployment, generated URL are missing the /myapp/ (/myappdev/) segment.

You can prefix your routes with /myappdev by adding it to your app/config/routing.yml file under the prefix key.
If you use relative URLs for the resources then you won't have a problem with the domain it's on and it will work anywhere you put it.

Related

Having different image url paths depending on stage

to preface: Im running a vue / spring webapp. My application on localhost runs under
"localhost:8080/application/"
while on DEV and TEST it runs under http://application-dev/ and http://application-test/ - so the /application prefix is missing.
In my sass I have the following image url paths: url("/application/image.png")
And on the DEV and TEST webservers I made redirects from /application to / to have it find the images.
Now I want to remove the "/application" part from my images and still get it to work on localhost.
Is there any way I can have a variable in my sass like "{contextpath}/image.png" and let the Spring webapp fill in the contextpath depending on where its deployed? So if I deploy at localhost the path would be ="/application" and if I deploy on test it would need to be equal to an empty string.
Is this even possible? tyvm

Symfony 4 front controller

Symfony 4 resigns on app.php and app_dev.php front controllers. Now it will be only one index.php. We can manipulate dev and prod environment in .env file. Please tell me is it only one way to change environment? I can't do that from the browser (as it was previous app and app_dev files)?
You control what is in the index.php file, so you can arrange to include a different env file according to the rules that you decide.
For example, you can set a variable in the Apache vhost or Nginx FastCgi configuration, based on the URL you are visiting from - such as APP_ENV=/home/myname/app-name/dev.env or on a live server: APP_ENV=/etc/app-name.prod.env set as you like, or you could list both of them in the index.php and choose which one from there - although taking the option out of the code and setting it in a server configuration would probably be safer in the long term.

serve application in subfolder instead of root domain

I deployed my app in example.com/app but all my routes are broken.
Oops, looks like there's no route on the client or the server for url: "http://example.com/app/."
I can try to manually prepend to all routes /app/ subfolder but it doens't seem the right approach, especially since i use a cms package (orionjs) to generate the /admin interface, which doesn't have support to change the admin path.
Is there any way to prepend the /app folder to all routes by default?
What i find strange is that i defined ROOT_URL to http://example.com/app/ but iron router seems to ignore it. Did i skip a step ?
Unlike many web platforms (ex: php), the folder structure under your app does not map automatically to routes. If you're using iron-router you basically define what layout maps to what route. The layout can be defined in an HTML file in any folder (except under /server or /public) at any depth. You can also add any extra depth you want to any route in iron-router by prepending app/ or whatever you want to your route definitions. Your ROOT_URL should remain http://example.com/

Symfony: generate prod url in dev environment

I am wondering if it is possible to choose environment when generating urls with the symfony routing component.
In a controller
$this->generateUrl($route, $params);
generates / in prod envrionment and /app_dev.php in dev.
There doesn't seem to be a parameter for the environment so that you could generate productive urls in dev environment. I just don't want to use something like str_replace all the time.
This would be great:
$this->generateUrl($route, $params, 'prod');
For your understanding, I am working on a cms project where I have to match uris against the database where they are stored without app_dev.php.
Any ideas?
More of a hack than a proper solution, you can set the Context's $baseUrl to be '' (as it would in production environment) before calling the generateUrl and reset-ting it back after the call. The RequestContext->getBaseUrl is consulted each time the complete Url is built.
In our case, we had to build Urls without the app_dev or app.php because our frontend was an AngularJS based application matching the URLs. In this case, since we dint want the app_dev or app.php at all, we created an EventListener that does a
$this->router->getContext()->setBaseUrl('');
Router component workflow doesn't include any of app.php or app_dev.php files. It only works with the pattern which comes after php file in the query string, whatever that file is.
So you're not able to do that. You only can use .htaccess file config to manage what file will be used as a default one, no more.

Add subdirectory for locale based URL existing ASP.NET website, resolve relative paths correctly

Existing ASP.NET (MVC and webforms hybrid) website displays translated content. The language is based on a cookie that stores the user's preference. There is no change in the URL when the user changes the setting. The content is reloaded in the preferred language. For SEO, the locale should be included in the URL ( support.google.com/webmasters/answer/182192?hl=en).
I've tried the following:
1) Use URL Rewrite Module: (http://www.iis.net/learn/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables)
Issues:
- All hyperlinks and redirects still point to the old URL without the locale.
- Complex outbound rules required based on the folder structure and usage (mixture of absolute paths and relative paths e.g. ../, ~/, /).
- Also need to disable static compression as per documentation
- Performance considerations due to large size of Html.
- Postback results in runtime exceptions due to issue in the relative path rewrite.
- Paths defined in script files (ajax loading etc) are a huge challenge
- Base tag does not work as expected, because the Rewrite Module seems to append ../ (http://www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms#Using_tilda)
2) IIS 7.5 Virtual Directory: Create Virtual Directory for each language and point it to the root. i.e. www.example.com is the root and www.example.com/fr-ca/ is a virtual directory mapped back to the root
Issues:
- Runtime exception in config file saying that the virtual directory needs to be converted to application
- Converting it to application gives 500.19 error due to duplicate entries in the web config (since the virtual directory is pointing back to the root)
- I tried moving the root to another subdirectory (i.e. have a physical directory for each language) to avoid web config conflicts, but that is resulting in some sort of "kernel" error. Also, this would mean changing the physical structure of the application, and also address routing issues
3) Using sub-domains:
I have also considered using sub-domains and hosting the application independently for each language, but this has a lot of drawbacks, including having to address scalability, single sign on, cookies, domain specific stuff like analytics etc.
So what is the least painful way to include a language sub-directory in the URL, and make all links relative to that sub-directory?
Note: The site contains a mixture of absolute paths and relative paths e.g. (../, ~/, /) sometimes used in conjunction with ResolveClientUrl, ResolveUrl
In the end, we went with option 2, with the below steps:
Create a new folder, deploy a copy of the application to the new folder. The new folder should be in a different directory from the root application.
Create a new virtual application* (not virtual directory) under the root application; 1 for each new language, pointing to the new folder. (If the need arises in the future, any of the virtual applications can point a different folder customized for that specific language)
In the new folder, remove the modules and handlers sections in the system.webServer section of the web.config file (they will be inherited from the parent web.config)
If you are using SQL session state, you will need to specify a custom Application Name in the web.config, and modify TempGetAppID stored procedure so that the Application Name is the same across all the virtual applications. See the following (http://blogs.msdn.com/b/toddca/archive/2007/01/25/sharing-asp-net-session-state-across-applications.aspx)
Hopefully, all the links are resolved on the server side using Url.Content (MVC) or ResolveUrl (webforms). If not, they need to be fixed. Any paths specified in javascript would not automatically resolve to the virtual application either (they would still be resolved to root application)
Test the heck out of it. Each and every link. (A tool like ScreamingFrog may help to make sure that no 404s are returned, methinks. But it wouldn't solve HTTP POST)
Note that depending on custom error handling, and any existing URL rewrite rules, the steps maybe different.
Summary: option 1 (URL Rewrite) is totally impractical. Option 2 (sub-directory) is the most practical solution, however it is not quite as straightforward as it should've been.

Resources