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 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?