Symfony version: 3.0
I have set multiple sub-domains for my project:
www.example.com, en.example.com and so on.
for one article page the url is:
www.example.com/article-1.html
en.example.com/article-1.html
if i add a sub-domain for the current domain:
article.www.example.com, article.en.example.com
the article.www.example.com is not good solution, i want to remove the www sub domain is article.example.com, when user open the en.example.com, the article.en.example.com is working.
how to do it?
i don't want to make a route file for each language site.
You can do it on the main routing file in /app/config by adding an host field at the same level as your path field and default field. The host field should contain the domain and subdomain you want, like in this example :
english_homepage:
path: /
host: article.example.com
default: { _controller: AcmeDemoBundle:Main:articles }
main_homepage:
path: /
host: www.example.com
default: { _controller: AcmeDemoBundle:Main:homepage }
You can also use placeholder, parameters, and other possibilities.
With them, you should be able to create variable subdomains to fit your needs.
For more information, read this : How to Match a Route Based on the Host
Related
I own an app in the Google Playstore.
This is accessible under the following url:
https://play.google.com/store/apps/details?id=#APPID#
#APPID# was used as a cover code.
Now I wanted to redirect the default url to the playstore URL with my Nginx proxy manager.
Means: example.org => https://play.google.com/store/apps/details?id=#APPID#
I have now tried many settings.
Correct me if I am wrong but I have applied the following configuration:
Domain Names: (example.org)
Scheme: auto
Forward Domain: https://play.google.com/store/apps/details?id=#APPID#
HTTP Code: 308
Perserve Path: Yes
Block COmmon Exploits: Yes.
And I add a SSL Certificate to my example.org
Force SSL: Yes
Everything else: No
it once (almost) worked and redirected me to https://play.google.com/store/apps/details?id=#APPID# /
(notice the / ) which is not recognized as url
Thanks in advance
I am trying to get an old project (not made by me) up and running, and I see that the routes are configured in some peculiar format. This is a typical route config:
customer_home:
path: /customer
host: "web.{domain}"
defaults:
_controller: "BackendBundle:Customer:index"
domain: "%domain%"
methods: [get]
options:
expose: true
requirements:
domain: '%domain%'
Now, I grepped the source code and found domain in the config files. It was null by default and by setting it to localhost:8000 I was able to at least load the root without complaints about %domain%. Now it complains about not finding a matching route, which makes sense, as none was configured. What was configured (which I found by doing console debug:router) was a root route for admin.{domain} and web.{domain}. I assume this means that if the domain is myapp.com, there should be routes configured for admin.myapp.com/ and web.myapp.com.
This is a local development setup, running on 127.0.0.1:8000, so I tried adding this to /etc/hosts:
127.0.0.1 web.localhost admin.localhost
I was now hoping that going to web.localhost:8000 would load a route, but none was matched. I still get NotFoundHttpException, but now I no longer understand why ... How can I configure this setup so that I can load the web and admin subdomains on my development machine? Other routes, like /api/1/doc, works fine.
I was not far off. The answer was to simply drop the port portion of what I had entered as the domain setting. So domain: localhost did the trick. The server is by default running on port 8000, no matter the setting, so it was not needed. I can now access web.localhost and admin.localhost (after adding them as host aliases for the loopback device in /etc/hosts).
I am developing a REST API using dropwizard. The resource can be accessed using https://<host>:port/item/1. As it can be seen there is no URI prefix. If I have to configure a URI prefix what needs to be done. Can it be configured in yaml configuration file?
Thanks!
Yes the URI prefix a.k.a root path can be configured in YAML. You could use the simple server factory configuration. It's simple, add these two lines in your YAML. I've used 'api' as the prefix. You can replace it with the URI prefix you want.
server:
rootPath: '/api/*'
A slightly more elaborate server configuration looks something like this,
server:
adminConnectors:
-
port: 18001
type: http
adminContextPath: /admin
applicationConnectors:
-
port: 18000
type: http
rootPath: /api/*
type: default
You can refer to this example https://github.com/dropwizard/dropwizard/blob/master/dropwizard-example/example.yml for server and other configuration details.
It's also a good idea to go through this if you are just getting started with dropwizard http://www.dropwizard.io/0.9.2/docs/getting-started.html
I have a website that I'm testing locally using domain.lc. The website has a subdomain sub.domain.lc that routes to a different controller, like this:
my_bundle:
host: sub.domain.lc
resource: "#MyBundle/Controller/"
type: annotation
prefix: /
The subdomain routes to my bundle because of the host, but I would like it to also route to this bundle using sub.domain.com. Is there a way to ignore the top level domain using the host?
You can use placeholder like this:
my_bundle:
resource: "#MyBundle/Controller/"
type: annotation
prefix: /
host: "{domain}"
defaults:
domain: "%domain%"
requirements:
domain: "sub\.domain\.(lc|com)"
But there is a problem with generating absolute URLs. It depends on where your app is currently running (loc or com) and you need to specify it as container parameter (parameters.yml is good place). Link to similar problem.
Although kba did provide an answer that helped me very much and I will in fact accept his answer as the right one, I want to show you what my route ended up looking like:
my_bundle:
host: sub.domain.{tld}
resource: "#MyBundle/Controller/"
type: annotation
prefix: /
requirements:
tld: lc|nl
defaults:
tld: nl
I didn't use the Service Container Parameter in my route, because I know my domain won't change. Only my top level domain can change.
I can try to map the url the next way:
en.test.example.local | en.example.com
AND
admin.test.example.local | admin.example.com
With admin I don't have any problem working fine but, when I try to begin the uri with a variable the symfony say:
Malformed inline YAML string ({locale}{enviroment}example.{domain})...
The config is the next:
# web urls
example_web:
host: {locale}{enviroment}example.{domain}
requirements: { locale: en , enviroment: .|.\w+., domain: local|com }
resource: "#ExampleWebBundle/Resources/config/routing.yml"
prefix: /
# admin urls
example_admin:
host: admin{enviroment}example.{domain}
requirements: { enviroment: .|.\w+., domain: local|com }
resource: "#ExampleAdminBundle/Resources/config/routing.yml"
prefix: /
If I put this:
# web urls
example_web:
host: en{enviroment}example.{domain}
requirements: { locale: en , enviroment: .|.\w+., domain: local|com }
resource: "#ExampleWebBundle/Resources/config/routing.yml"
prefix: /
working fine, but is a multilanguage application and I need the multilanguage by "subdomain"
My mistake was very very simple :P
host: "{_locale}.{enviroment}.example.{domain}"
missing double quotes furthermore using _locale for save in session for translate thank cheesemacfly
Why don't you use the _local parameter (symfony.com/doc/master/book/…)?
Well I resolved it with this information: Symfony2 Routing - route subdomains
But if anyone know a better answer, please tell me :)