duanqiang9212 2013-01-16 23:23
浏览 70
已采纳

Yii SEO友好语言启用网址

I followed this tutorial .

What I want to achieve is something like

http://something.com/language/controller/action

But I'm getting

http://something.com/controller/action?language=en&id=1

As far as I know, here is part where URL generation goes. But I can't figure out how to fix it.

What am I missing?

  • 写回答

3条回答 默认 最新

  • du9537 2013-01-16 23:38
    关注

    Use an htaccess file (if you are unfamiliar with htaccess check for a tutorial on google)

    add the following lines in it

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)(.*)$ /index.php?page=$1&request=$2
    

    WIth this rule lets assume you have the domain.com and a user requests the following url

    http://www.domain.com/news/December/politics/Titlearticle1

    The above rule will break this url request and assign

    $_GET['page'] = 'news';
    

    and

    $_GET['request'] = '/December/politics/Titlearticle1';
    

    Now in you php script

    you could

    1) validate the page request

    2) explode $_GET['request'] to further validate your request

    $request_parts = explode('/',$_GET['request']);
    

    3) validate everything! this is very important or your site might be vulnerable.

    like so:

    if($_GET['page'] == 'news')
    }
      include 'news.php';
    {
    else if ($_GET['page'] == 'home')
    {
      include 'home.php';
    }
      else
    {
      include 'error.php';
    }
    

    This is some pretty basic concept but you can expand it according to your needs...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题