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
}
2
  • 1
    You may have the wrong idea about what "rewriting" means. Start here: stackoverflow.com/a/20563773/476 Commented Jun 22, 2015 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 Commented Jun 22, 2015 at 13:20

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.