递归mod_rewrite的搜索引擎友好的URL [英] Recursive mod_rewrite for search engine friendly urls

查看:187
本文介绍了递归mod_rewrite的搜索引擎友好的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在读通过<一个href="http://stackoverflow.com/questions/117931/apache-modrewrite-one-rule-for-any-number-of-possibilities/119306#119306">$p$pvious解决方案以递归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/...

到正规的查询字符串:

to a regular query string:

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的搜索引擎友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆