如何在 url 开头使用语言标识符
How to use a language identifier at the start of url
我正在使用:http://localhost/en/index.php 来识别当前网站的语言。
但是,我正在寻找这样的方法:http://en.localhost/index.php
也许某些网络服务器配置或框架会有所帮助。
经过我的所有研究,我无法找到解决方案。
谢谢你,祝你有愉快的一天。
如果您使用 wildcard
域配置,您可以做很多选择。假设您在 DNS 中有以下条目:
*.example.com 127.0.0.1
example.com 127.0.0.1
这会将 example.com
下的所有域和子域重定向到一个地方。这样的东西也可以在 Apache 中配置。
ServerName example.com
ServerAlias *.example.com
而且他们都去同一个地方。在PHP中,您可以使用:
$lang = str_replace(".example.com", "", $_SERVER["HTTP_HOST"]);
并且根据$lang
中的变量你可以做到。如果你想为 localhost
做这件事,你需要这样设置你的 Apache 指令:
<VirtualHost *:80>
ServerAdmin me@localhost.com
DocumentRoot "C:/www"
ServerName localhost
ServerAlias *.localhost
<Directory "C:/www">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
我正在使用:http://localhost/en/index.php 来识别当前网站的语言。
但是,我正在寻找这样的方法:http://en.localhost/index.php
也许某些网络服务器配置或框架会有所帮助。
经过我的所有研究,我无法找到解决方案。 谢谢你,祝你有愉快的一天。
如果您使用 wildcard
域配置,您可以做很多选择。假设您在 DNS 中有以下条目:
*.example.com 127.0.0.1
example.com 127.0.0.1
这会将 example.com
下的所有域和子域重定向到一个地方。这样的东西也可以在 Apache 中配置。
ServerName example.com
ServerAlias *.example.com
而且他们都去同一个地方。在PHP中,您可以使用:
$lang = str_replace(".example.com", "", $_SERVER["HTTP_HOST"]);
并且根据$lang
中的变量你可以做到。如果你想为 localhost
做这件事,你需要这样设置你的 Apache 指令:
<VirtualHost *:80>
ServerAdmin me@localhost.com
DocumentRoot "C:/www"
ServerName localhost
ServerAlias *.localhost
<Directory "C:/www">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>