8000 hostname_pattern not working · Issue #6821 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

hostname_pattern not working #6821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MichaelHindley opened this issue Jan 21, 2013 · 13 comments
Closed

hostname_pattern not working #6821

MichaelHindley opened this issue Jan 21, 2013 · 13 comments
Labels

Comments

@MichaelHindley
Copy link

Trying to use hostname_pattern as per http://symfony.com/doc/master/components/routing/hostname_pattern.html

like this:
routing.yml

#Bike
bike:
    prefix: /
    pattern: /
    hostname_pattern: *.cykelverkstad.nu
    defaults: { _controller: EmpireBikeBundle:Homepage:index }

using this composer.json require:

{
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.2.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.2.*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.2.*",
        "symfony/swiftmailer-bundle": "2.2.*",
        "symfony/monolog-bundle": "2.2.*",
        "sensio/distribution-bundle": "2.2.*",
        "sensio/framework-extra-bundle": "2.2.*",
        "sensio/generator-bundle": "2.2.*",
        "jms/security-extra-bundle": "1.4.*",
        "jms/di-extra-bundle": "1.3.*",
        "jms/serializer-bundle": "0.9",
        "friendsofsymfony/rest-bundle": "0.10.0"
    },
}

Debug-bar shows symfony as 2.2.

Getting this error:
[InvalidArgumentException]
The routing file "D:/Dev/wamp/www/empire/app/config\routing.yml" contains u
nsupported keys for "bike": "hostname_pattern". Expected one of: "resource"
, "type", "prefix", "pattern", "path", "hostname", "schemes", "methods", "d
efaults", "requirements", "options".

It says "hostname_pattern" is a unsupported key, even though Symfony is on 2.2.

@wouterj
Copy link
Member
wouterj commented Jan 21, 2013

We have changed the name of some important options in Symfony2.2 last week ( #6738 ). You should use hostname instead of hostname_pattern. For more information, look in the UPGRADE-3.0.md file in the root of the symfony project.

@MichaelHindley
Co 8000 py link
Author

I tried using only hostname, but then the eror is like this:
[Symfony\Component\Yaml\Exception\ParseException]
Reference ".cykelverkstad.nu" does not exist in "/var/www/empire/app/c
onfig/routing.yml" at line 0.

Is this a bug or is there no functionality to support *.domain.com ?

@stof
Copy link
Member
stof commented Jan 21, 2013

* is a special character in YAML when using it at the beginning of values. So you need to quote the string.

@MichaelHindley
Copy link
Author

Tried that already as well, but the route doesn't match then so I figured that wasn't the correct way to do it. You mean "*.domain.com", correct?

@lazyhammer
Copy link
Contributor

I think you have to use something like this:

hostname: {any}.domain.com

@MichaelHindley
Copy link
Author

That gives a malformed YAML error,
but if its quoted it works as long as the subdomain isn't empty, but a direct entry like "domain.com" doesn't match the route.

Tried these to no success:

doesnt match "cykelverkstad.nu"

bike:
prefix: /
pattern: /
hostname: "{any}.cykelverkstad.nu"
defaults: { _controller: EmpireBikeBundle:Homepage:index, any: * }

fails with no route found on *.cykelverkstad.nu and cykelverkstad.nu

bike:
prefix: /
pattern: /
hostname: "{any}cykelverkstad.nu"
defaults: { _controller: EmpireBikeBundle:Homepage:index, any: * }

fails with missing mandatory parameter

bike:
prefix: /
pattern: /
hostname: "{any}.cykelverkstad.nu"
defaults: { _controller: EmpireBikeBundle:Homepage:index }

fails with no route found

bike:
prefix: /
pattern: /
hostname: "{any}"
defaults: { _controller: EmpireBikeBundle:Homepage:index, any: cykelverkstad}

Seems like I'm either missing something very basic, or it's not that easy to add a route for "*domain.com".

@lazyhammer
Copy link
Contributor

Use a requirement like this:

hostname: "{any}"
requirements:
    any: "(?:[^\.]++\.)?domain.com"

@MichaelHindley
Copy link
Author

hostname: {any}
requirements:
any: (?:[^.]++.)?domain.com

When going to www.domain.com results in:

[1/2] MissingMandatoryParametersException: Some mandatory parameters are missing ("any") to generate a URL for route "domain_homepage".

@Tobion
Copy link
Contributor
Tobion commented Mar 7, 2013

The first part of the report is just bad usage and the second part a duplicate of #6857.

@Tobion Tobion closed this as completed Mar 7, 2013
@MichaelHindley
Copy link
Author

Either way, there is still no way to match anything.domain.anything
Why are both issues closed? Should we open a new one?

@Tobion
Copy link
Contributor
Tobion commented Mar 7, 2013

You can match anything in the domain you want. You just need to understand how its working.
For example you can do host: {subdomain}.domain.{tld}. And the error you give above has nothing to do with matching. Just read it carefully.

@MichaelHindley
Copy link
Author

I'm not talking about {subdomain}.domain.{tld}, I'm talking about {}.domain.{}, where * = anything, without being defined in configuration somewhere. The original error was solved long ago and the discussion has been revolving about matching .domain.. Like, I have a service where the subdomain is always a clients username, out of several thousand, the main domain is always the same, and the tld can be any of over 50 different.

If I'm missing something in the Symfony 2 docs and on the Github discussions then it's of course my own fault, but judging by other peoples experiences and comments, this is not actually possible. I may not be the best at programming , since I'm on the business side of things, but I like to think of myself on at least a junior dev level purely out of necessity to understand my employees. English is my third language but I always try to report any faults I find and things that I feel can be improved even though I lack the knowledge to debug it in depth myself, to try and give back to the people that provide the tools that pay for my house.

Having said that, we still haven't found a way to match ANY subdomain, permit it to be empty and have any tld, with a single route rule. We have of course found workarounds but the way we do it now seems weird and backasswards(settings apache vars) in this day and age.

@Tobion
Copy link
Contributor
Tobion commented Mar 8, 2013

The thing is that optional placeholders are not implemented yet for the host.
So given {subdomain}.domain.com with requirement for subdomain = .* it would match foo.domain.com and .domain.com but not domain.com (because the dot is statically required). As a workaround until this feature is implemented, you can use two routes with different host patterns. Hope I could clear things up.
I opened a new feature request #7306.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
0