0

i'm creating a index.php file for redirect all website to specific host I'd like create a little php script that read url and redirect based on specific filter.

for example: if url = (everything).domain1.com redir to default1.php if url = (everything).domain2.com redir to default2.php in all other case that not like first or second redir to default3.php

this is possible with php? i must use $_SERVER['HTTP_HOST'] or can I use other method?

6
  • For that task will be better to use RewriteCond in .htaccess Commented Apr 15, 2017 at 12:13
  • yes like previous comment do this in htaccess load of questions like this on SO Commented Apr 15, 2017 at 12:14
  • yes, i know, but i can't use .htaccess Commented Apr 15, 2017 at 12:16
  • why cant you use it? if you have ftp access you can use it Commented Apr 15, 2017 at 12:17
  • and if i use .htaccess what can I write inside file? Commented Apr 15, 2017 at 12:19

1 Answer 1

1

i resolved with:

    <?php 
$domain = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
if (strpos($domain,'domain-name.com') == true) {
    header('location: /index2.php');
    exit();
} else {
    header('location: /index3.php');
}
?>

but not redirect...

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

Comments

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.