1

I'm working with an environment for testing purposes based on a few magento versions over a nginx + php-fpm + mysql stack, i puts each distribution in a different folders and in the nginx vhost config file i'm using the following sentence:

server_name ~^(?&ltversion&gt.+)\.magento\.test$;
root [root_path]/distro/$version;

So until here i can get any dinamic url mapped to its folder

ce107.magento.test => [root_path]/distro/ce107/
ce108.magento.test => [root_path]/distro/ce108/
ce109.magento.test => [root_path]/distro/ce109/

The problem starts when i try to use the "host name label" to switch websites on each distribution:

us.ce107.magento.test, ar.ce107.magento.test ... 

because nginx looks for: [root_path]/distro/us.ce107/ and [root_path]/distro/ar.ce107/ folders.

So i need to parse and retrieve the values of:

 [ws_code].[version].magento.test  

and i can't figure out how to do it, maybe i could use "map $host $ws_code {}" to parse $ws_code value, and apply some regex to remove "ws_code." part from the $version

BTW obviously i can do it "harcoded" but i want to keep it "dinamic"

Can someone give a hand with this? Thanks in advance!

MauroNigrele
  • 113
  • 1
  • 4
  • Please specify, where `[ws_code].[version].magento.test` should point by example? Also do you need both 3rd and 4th level domain support (i.e. both with and without `[ws_code]`) or just 4th devel domain support? – jollyroger May 11 '15 at 07:35
  • Ok @jollyroger i forgot to explain this part... based on previous example, both `us.ce107.magento.test` and `ar.ce107.magento.test` must point to same folder `([root_path]/distro/ce107)` so the 4th level is just used as a var for send it to php ( _fastcgi_param MAGE_RUN_CODE $ws_code;_ ) - Very good point about 3rd and 4th level support, in some case maybe i'll need it eg: `us.ce107.magento.test` and `ce107.magento.test` support, but this is just an "extra" because i can force it to use always a 4th level url. Thanks! – MauroNigrele May 11 '15 at 07:51

1 Answers1

1

The (?<version>.+) regexp will use greedy match and assign it to $version variable. You could do just the same to match both ws_code and version:

server_name ~^(?<ws_code>.+)\.(?<version>.+?)\.magento\.test$;
root [root_path]/distro/$version/$ws_code;

I've used greedy match for [ws_code] and non-greedy for [version]. Also I'd use something more deterministic like [a-zA-Z0-9-]+ to exclude domain separator dot sign from possible match like this (in this case we don't need to check wether match algorithm is greedy or not):

server_name ~^((?<ws_code>[a-z]+)\.)?(?<version>[a-zA-Z0-9-]+)\.magento\.test$;
root [root_path]/distro/$version;

Additional ()?braces over ws_code matchig will allow this configuration to match both 3rd level domain with just one variable available and 4th level domain with two variables available. You might want to assign a default variable for ws_code.

jollyroger
  • 1,650
  • 11
  • 19