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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀