0
$filename = "domainin.txt";

$fp = @fopen($filename, 'r'); 

if ($fp) { 
 $array = explode("\n", fread($fp, filesize($filename)));

}
    $num = count($array);
    for ($i=0;$i<$num;$i++){
    $domains = explode(',', $array[$i]);
    $result[] = $domains;
    }

    foreach($result as $val) {
        if($_SERVER['REQUEST_URI'] == $val[0]){
            header ('HTTP/1.1 301 Moved Permanently');
            $host  = $_SERVER['HTTP_HOST'];
            $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/');
            header('Location: '.$val[1]);
            exit(0);
        }
    }

I have this which reads a txt file and reroutes URL's. However, a URL has é in the address and it won't read it and simply ignores it. How can I force it to read and recognize the special characters?


Example of text file is as follows...

/path/to/url/original-oné/, /path/to/url/new/
/path/to/url2/original/, /path/to/url2/new/
/path/to/url3/original/, /path/to/url3/new/

It's not reading /original-oné/ as the é is like that, it totally skips

Krupal Panchal
  • 1,553
  • 2
  • 13
  • 26
Chris Gwynne
  • 47
  • 2
  • 7
  • What does `$val` contain ? – executable Nov 14 '19 at 13:33
  • the text file has /path/to/old/url,/path/to/new/url – Chris Gwynne Nov 14 '19 at 13:38
  • Just a though i think you need to do something with encoding.. – Raymond Nov 14 '19 at 13:42
  • looks like your webserver can't understand the provided url, perhaps [this answer](https://stackoverflow.com/a/913885/374509) could help – csminb Nov 14 '19 at 14:27
  • I can't reproduce this on my machine. Is the error in the first `for()` loop or in the second? – Martin Wickman Nov 14 '19 at 14:29
  • No errors are produced Martin, it simply ignores the letter. For example, if I add a URL with é to the text file, it ignores it and doesn't redirect, however, any URL's without é will redirect as normal. – Chris Gwynne Nov 14 '19 at 14:32
  • @ChrisGwynne Any UTF-8 characters are ASCII encoded and sent as URLs can't contain those symbols as is. Are you sure `$_SERVER['REQUEST_URI']` has the exact string to be matched? Check this in PHP command line and not on browser, as it might render it correctly giving an impression that it is what it is. – nice_dev Nov 14 '19 at 14:51

0 Answers0