0

Is it possible to use rewrite rules depending on a php variable? for example, i got 10 websites with 10 domains. each website got a "config.php". Inside this file, there is a variable called $city.

can i rewrite the url in this style?

pseudocode:

if ($city == 'berlin') {
page.php = page-berlin.php
}
Boeringer
  • 185
  • 1
  • 1
  • 11
  • 1
    You may have the wrong idea about what "rewriting" means. Start here: http://stackoverflow.com/a/20563773/476 – deceze Jun 22 '15 at 12:23
  • thanks for your comment. when rewriting is the wrong solution for my problem, what should i use instead to "rename" files dynamically? xyz.tld/page1.php to xyz.tld/page1-berlin.php for example – Boeringer Jun 22 '15 at 13:20

2 Answers2

2

Have a look at this answer in which changes the url of the browser without refreshing the page, it can solve your problem if it is just the look of the url you want.

Community
  • 1
  • 1
alexandreferris
  • 662
  • 1
  • 8
  • 27
1

You could write a simple routing script that all of your domains are pointed to. Using $_SERVER['server_name'] you then loading the required config file, which has the file it needs to include to give you the required output, or it loads in the config.php file, which sets a constant using define('CITY', 'BERLIN') which the rest of your script can use.

This isn't rewriting, but it should work for your situation.

  • thanks for your reply, but i dont really understand it. example: on "xyz-dubai.tld all files (page1.php, page2.php) should renamed to page1-dubai.php, page2-dubai.php. on xyz-berlin.tld the page1 should renamed to page1-berlin.php – Boeringer Jun 22 '15 at 13:14
  • 1
    When I get home later I will comment my answer with proper code - I just noticed the question in new and didn't have time yesterday earlier. – Thomas Gillespy Jun 23 '15 at 11:19