用于搜索引擎友好网址的递归 mod_rewrite

Recursive mod_rewrite for search engine friendly urls(用于搜索引擎友好网址的递归 mod_rewrite)
本文介绍了用于搜索引擎友好网址的递归 mod_rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我一直在阅读以前的解决方案 递归 mod_rewrite 问题类似于我正在尝试做的,不同之处在于我通过 index.php 文件发送所有查询,因此不需要在询问.

I've been reading through a previous solution to a recursive mod_rewrite problem that is similar to what I'm trying to do, the difference is I'm sending all queries through an index.php file and so don't need to specify the script within the query.

本质上我想在搜索引擎友好的 url 中递归转换任意数量的参数:

Essentially I want to recursively convert any number of parameters within a search engine friendly url:

example.com/param1/val1/param2/val2/...

到常规查询字符串:

example.com/index.php?param1=val1&param2=val2&...

到目前为止,我的尝试都没有成功:

So far I've been unsuccessful in in my attempts though:

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^/]+)/([^/]+) $1=$2&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ index.php?%1 [L]

有人可以提供任何建议吗?

Would anyone be able to offer any suggestions?

推荐答案

我从另一个问题复制了解决方案并像这样修改:

I copied the solution from that other question and modified it like this:

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*/)?([^/]+)/([^/]+) $1?$2=$3&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^.*$ index.php?%1 [L]

它几乎做同样的事情,除了在第一个规则中,第一个匹配是可选的,在第二个规则中,匹配在所有其他对匹配之后剩下的任何部分.

It does nearly the same thing, except in the first rule, the first match is optional and in the second rule, the match is on whatever is left after all the other pairs are matched.

对于奇数个参数,第一个参数被忽略.

For an odd number of parameters, the first parameter is ignored.

注意,如果您希望有很多参数,您可能需要更改一些设置.

One note, if you expect to have a lot of parameters, you may have to change some settings.

将类似的内容添加到您的 .htaccess 文件中

Add something like this to your .htaccess file

RewriteOptions MaxRedirects=20

和类似这样的东西到你的 apache conf 文件

and something like this to your apache conf file

LimitInternalRecursion 20

选择您需要允许的任意数量的递归(对)而不是20"(默认为 10).

Instead of "20" pick whatever number of recursions (pairs) you need to allow (the default is 10).

这篇关于用于搜索引擎友好网址的递归 mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)