douyou3619 2014-06-16 21:52
浏览 42
已采纳

基于htaccess语言的虚拟子文件夹

Good nigh, Im trying to create virtual subfolders for user's browser language.

So i have the following folder structure:

www/
    Core/
        Classes/
            Autoloader.Class.php
            Smarty.Class.php
            Database.Class.php
            LoadingOrder.json
        Libraries/
            Smarty.Class.BC.php
            Smarty.Class.php
            SmartyModules/
                ..
        Modules/
            Autoloader.Module.php
            Wall.Module.php
            Account.Module.php
            LoadingOrder.json
        Engine.php
        Initialize.php
    Templates/
        Default/
            css/
                main.css
                style.css
                ErrorHandler.css
            images/
            javascript/
                jquery.js
            Main.tpl
            User.tpl
            ErrorHandler.tpl
    .htaccess
    index.php
    user.php
    ErrorHandler.php

The thing i need, is to create multilingual website.

For example: User want to go to his/her page: http://site.domain/user

The thing i want to implement, is that based on his browser language, it will redirect him to
http://site.domain/en/user - if he speaks English,
http://site.domain/ru/user - if he speaks Russian,
http://site.domain/pt/user - if he speaks Portugese.

The thing is, these language subfolders should be only virtual, and the all their requests should be made to only user.php, which is one in the root directory.

I've been googleing, and found that on http://battle.net - there is kind of system like this.

So is it possible to create system like this via htaccess, or its purely php?

  • 写回答

1条回答 默认 最新

  • dst2017 2014-06-16 22:06
    关注

    Put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC]
    RewriteRule ^user/?$ /%1%{REQUEST_URI} [L,NC,R]
    
    RewriteRule ^([a-z]{2})/(user)/?$ /$2.php?lang=$1 [L,NC,QSA]
    

    This will redirect /user to /en/user in browser but will load /user.php?lang=en silently.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了