如何删除index.php并从url中隐藏参数lang?

如何删除index.php并从url中隐藏参数lang?,php,.htaccess,mod-rewrite,url-rewriting,Php,.htaccess,Mod Rewrite,Url Rewriting,我有以下网址 http://localhost/apps/site/index.php?lang=es 我想使用.htaccess使其如下所示 http://localhost/apps/site/es .访问规则 重新启动发动机 重写基/ 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D 重写cond%{REQUEST_FILENAME}-L 重写规则^(+?)/?$/index.php?lang=$1[L,QSA] 当我尝

我有以下网址

http://localhost/apps/site/index.php?lang=es
我想使用.htaccess使其如下所示

http://localhost/apps/site/es
.访问规则

重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-L
重写规则^(+?)/?$/index.php?lang=$1[L,QSA]
当我尝试此url
http://localhost/apps/site/es
直接将我重定向到
http://127.0.0.1/dashboard/

我尝试过此解决方案,但不适用于我:

  • 第一个条件是告诉模块仅当请求URI正好
    /apps/site/index.php

  • 第二个条件,如果第一个查询参数名称为
    lang
    ,且其值为单词。
    ()
    用于捕获参数值并将其保存在
    %1

  • 在规则中,我们告诉模块删除
    apps/site/index.php
    ,并通过
    /apps/site/%1
    重写它,同时用我们从第二个条件中捕获的值替换
    %1

  • QSD
    querystringdiscard标志是使模块不将查询附加到最终url(您必须在
    L
    标志之前设置它,这将工作
    [L,QSD]

现在如果你要求的话

http://localhost/apps/site/index.php?lang=es
它将被改写为

http://localhost/apps/site/es
您可以在此网站上测试和使用重写规则

  • 第一个条件是告诉模块仅当请求URI正好
    /apps/site/index.php

  • 第二个条件,如果第一个查询参数名称为
    lang
    ,且其值为单词。
    ()
    用于捕获参数值并将其保存在
    %1

  • 在规则中,我们告诉模块删除
    apps/site/index.php
    ,并通过
    /apps/site/%1
    重写它,同时用我们从第二个条件中捕获的值替换
    %1

  • QSD
    querystringdiscard标志是使模块不将查询附加到最终url(您必须在
    L
    标志之前设置它,这将工作
    [L,QSD]

现在如果你要求的话

http://localhost/apps/site/index.php?lang=es
它将被改写为

http://localhost/apps/site/es

您可以在此网站上测试和使用重写规则

您能告诉我们您是如何编写重写条件规则的吗?@catcon检查我的问题,请检查我的问题。我已添加了我的htaccess规则。当我尝试此url时,直接将我重定向到,为什么我觉得你在其他地方进行了另一次重写,并且它在你之前运行。你能告诉我们你是如何编写重写条件规则的吗?@catcon检查我的问题,请我添加了我的htaccess规则。当我尝试此url时,直接将我重定向到,为什么我觉得你在别的地方又重写了一次,而且在你之前就已经运行了..谢谢你的回答,但是这个解决方案对我不起作用。当你请求
http://localhost/apps/site/index.php?lang=es
重写了什么URL?没什么,仍然是同一个URL(),我尝试了这个解决方案,它成功了:RewriteEngine On RewriteCond%{HTTP_-HOST}^127.0.0.1/apps/site RewriteRule(.*)[R=301,L]RewriteCond%{HTTP:X-Forwarded-Proto}!https RewriteCond%{QUERY_-STRING}!*healthCheck=true.*RewriteRule^([a-zA-Z0-9.-]+)$index.php?lang=$1 RewriteRule^[a-zA-Z0-9.+]/$index.php?lang=$1是否重写此
http://localhost/apps/site/index.php?lang=es
到此
http://localhost/apps/site/es
?感谢您的回答,但此解决方案不适用于我。当您请求
http://localhost/apps/site/index.php?lang=es
重写了什么URL?没有,仍然是相同的URL()我尝试过这个解决方案,它的工作原理是:RewriteCond%{HTTP_HOST}^127.0.0.1/apps/site RewriteRule(.*)[R=301,L]RewriteEngine On RewriteCond%{HTTP:X-Forwarded-Proto}!https RewriteCond%{QUERY_STRING}.*healthCheck=true.*RewriteRule^[a-zA-Z0-9.+]index.php?lang=$1 RewriteRule^[a-zA-Z0-9.+]/$index.php?lang=$1是否重写此
http://localhost/apps/site/index.php?lang=es
到此
http://localhost/apps/site/es