mod_rewrite的重写example.com/page.php?v1=abc&v2=def到example.com/abc/def~~V重写、com、page、mod_rewri

2023-09-02 00:30:37 作者:不交电费瞎发啥光

使用阿帕奇的htaccess 的文件,我想重写网​​址 http://example.com/page.php?v1=abc&v2=def 的http://例子.COM / ABC / DEF

Using Apache's htaccess file, I am trying to rewrite the URL http://example.com/page.php?v1=abc&v2=def to http://example.com/abc/def.

到目前为止,我有:

Options +FollowSymLinks
RewriteEngine on
RewriteRule case-study/(.*)/(.*)/(.*)/(.*)/$ /case-study.php?$1=$2&$3=$4

不过,这似乎只是服务于实际文件 page.php 的URL不变。

有谁知道什么是正确的方式做到这一点还是什么可能是错误的上面?

Does anyone know what the proper way to do this or what might be wrong with the above?

推荐答案

您有它倒退。什么你从此改写先走,那么你正在改变它在去年底。以下可能不准确,但应接近你所需要的:

You have it backwards. What you're rewriting from goes first, then what you're changing it to goes at the end. The following may not be exact, but should be close to what you need:

的RewriteCond {%QUERY_STRING} ^ V1 =&AMP(*);

的RewriteCond {%QUERY_STRING} V2 =(。*)$

重写规则的情况下,study.php /案例研究/ 1%/ 2%/

下面是重写规则的文档了解更多详情: mod_rewrite的

Here's the RewriteRule documentation for more details: mod_rewrite

请注意,使用的规则和替代导致斜线将取决于您使用它的问题(见链接的文档)。在上面的例子中,%1和%2指回捕捉组中的第一和第二的RewriteCond。这里有一个页面,该页面介绍的方法: mod_rewrite的基于查询字符串参数

Note that the use of leading slashes on the rule and substitution will depend on the context you're using it in (see the linked documentation). In the above example, the %1 and %2 refer back to the capture groups in the first and second RewriteCond. Here's a page that describes that approach: mod_rewrite based on query string parameters