douyan4243 2016-07-06 07:58
浏览 40
已采纳

PHP假网址,复杂.htaccess rewrite_mod

I have real a lot about CakePHP, and php rewrite_mod, but i m so much confused about how to use it as i don't have knowledge about regex. how can i have something like this?

mywebsite.com/en/ => mywebsite.com/?lang=en

mywebsite.com/en/about => mywebsite.com/about/?lang=en

mywebsite.com/en/search/?query=Hello+World => mywebsite.com/search/?query=Hello+World&lang=en

so in the reality my files are like:

public_html/about/index.php
public_html/search/index.php
public_html/index.php

but i m faking it like

public_html/en/about/index.php
public_html/en/search/index.php
public_html/en/index.php

and need to conserve the URL, and PARAMETERS passed through GET, i don't understand how to setup a so complex url controller in .htaccess

i've also tried following this but not getting out, is there any sample project? cakephp 3 parameter url

  • 写回答

1条回答 默认 最新

  • dtpxi88884 2016-07-06 08:07
    关注

    Essentially, you rearrange the request URL. This means, you must capture (...) the parts separately, and put them together in the substitution $.... You also want to keep an existing query string, which requires the use of the QSA|qsappend flag. The RewriteCond is there to prevent a rewrite loop. If the rule was applied once, it shouldn't be used a second time.

    RewriteCond %{QUERY_STRING} !lang=
    RewriteRule ^(..)(.*)$ $2?lang=$1 [L,QSA]
    

    To learn more about regular expressions, see Apache - Regular Expressions.

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

报告相同问题?

悬赏问题

  • ¥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时遇到的编译问题