1

I have acquainted myself with the concept of percent encoding of URLs. Now I'm trying to use it in my HTML.

Say I have a HTML document named 한국 (Korean) which corresponds to the following percentage encoding: %ED%95%9C%EA%B5%AD.

My question is how to create a working link with that. Until now, I only had to deal with href in which only ASCII characters appeared, like so:

<a href="example.php">한국</a>

However, if I change this to either of the following

<a href="%ED%95%9C%EA%B5%AD.php">한국</a>
<a href="한국.php">한국</a>

with the target file named equally (i. e. %ED%95%9C%EA%B5%AD in the first case and 한국 in the second case), I get a 404 in the former and a PHP error message that the file was not found in the latter. The version with the actual Korean was just for testing purposes, I didn't expect that to work.

What am I doing wrong? I know that modern browsers convert this encoding to the actual UTF-8 characters, so I thought I could simply replace the corresponding part in the href and give the targer file the same name, but this does not work.

AlexM
  • 325
  • 4
  • 11
  • 1
    If you put `%ED%95%9C%EA%B5%AD.php` in link and name file `한국` - will it work? If yes, then I suppose it is best way to have it – iXCray Jul 31 '17 at 22:12
  • Sadly, this did not work either. But there must be a way, I mean, Wikipedia for example has been doing the same thing for years. – AlexM Jul 31 '17 at 22:16
  • 1
    Not same. It doesn't have .php files names in different languages. It has one "gateway" file like index.php that receives all requests and just reads and decode URI. It will need corresponding web-server configuration like mentioned here: https://stackoverflow.com/questions/38897172/rewrite-all-requests-to-php-script-on-nginx or https://stackoverflow.com/questions/38897172/rewrite-all-requests-to-php-script-on-nginx . From architecture point of view that solution will be more convenient than to have many php files with different names in different languages – iXCray Jul 31 '17 at 22:20
  • The thing I don't get about that is that somehow these URI that index.php reads and decodes must point to some content, so is it really that big a difference to have many .php files instead? – AlexM Jul 31 '17 at 22:32
  • Yes, you receive URI in some variable and then parse it using simple regular expressions or complex router solutions depending on what your goal is, and then decide what exactly you want to show your visitor. – iXCray Jul 31 '17 at 22:35
  • Ok, haven't thought about that before, interesting. However, I still don't understand why the problem described above in my question comes up. Maybe it's something about naming files. – AlexM Jul 31 '17 at 22:43
  • 2
    It seems that it has something to do with your web-server. I use nginx (latest), created 한국.php, and it is accessed both via /한국.php and /%ED%95%9C%EA%B5%AD.php in every browser I have. – iXCray Jul 31 '17 at 23:05
  • Interesting information, thank you for that, I will keep that in mind when I look for a server. On my computer, I use Wampserver32 (because none of this is online yet) on Windows 7. I've found out that the percent signs are to blame. Without them, it works, which is quite annoying for such a problem. – AlexM Jul 31 '17 at 23:16
  • 1
    start a proper VM to establish LAMP environment that will be used in real world. You will get utf compliant filesystem and positive experience with your project without such bugs, which, I believe, starts with WAMP, used mainly for students-lab-level practice. – iXCray Aug 01 '17 at 08:44
  • I have never used Linux before, so let me make it very clear: On a linux system, could I just name the file 한국.php and refer to it as href="한국.php" without any trouble? – AlexM Aug 01 '17 at 16:15
  • 1
    That's correct. You can – iXCray Aug 01 '17 at 16:16
  • All right, thank you very much! – AlexM Aug 01 '17 at 16:25
  • @iXCray: if you type `/한국.php` into a browser, it will not actually send `/한국.php` over HTTP, it will send `/%ED%95%9C%EA%B5%AD.php` instead. It is the web server's responsibility to decode that to `/한국.php` before it accesses the file system to open the file. – Remy Lebeau Aug 03 '17 at 23:36

0 Answers0