問題描述
我一直在閱讀以前的解決方案 遞歸 mod_rewrite 問題類似于我正在嘗試做的,不同之處在于我通過 index.php 文件發(fā)送所有查詢,因此不需要在詢問.
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.
本質(zhì)上我想在搜索引擎友好的 url 中遞歸轉(zhuǎn)換任意數(shù)量的參數(shù):
Essentially I want to recursively convert any number of parameters within a search engine friendly url:
example.com/param1/val1/param2/val2/...
到常規(guī)查詢字符串:
example.com/index.php?param1=val1¶m2=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?
推薦答案
我從另一個(gè)問題復(fù)制了解決方案并像這樣修改:
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]
它幾乎做同樣的事情,除了在第一個(gè)規(guī)則中,第一個(gè)匹配是可選的,在第二個(gè)規(guī)則中,匹配在所有其他對(duì)匹配之后剩下的任何部分.
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.
對(duì)于奇數(shù)個(gè)參數(shù),第一個(gè)參數(shù)被忽略.
For an odd number of parameters, the first parameter is ignored.
注意,如果您希望有很多參數(shù),您可能需要更改一些設(shè)置.
One note, if you expect to have a lot of parameters, you may have to change some settings.
將類似的內(nèi)容添加到您的 .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
選擇您需要允許的任意數(shù)量的遞歸(對(duì))而不是20"(默認(rèn)為 10).
Instead of "20" pick whatever number of recursions (pairs) you need to allow (the default is 10).
這篇關(guān)于用于搜索引擎友好網(wǎng)址的遞歸 mod_rewrite的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!