Recursive mod_rewrite for search engine friendly urls

前端 未结 4 1073
别那么骄傲
别那么骄傲 2020-12-30 18:11

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 throu

4条回答
  •  误落风尘
    2020-12-30 18:34

    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.

    Add something like this to your .htaccess file

    RewriteOptions MaxRedirects=20
    

    and something like this to your apache conf file

    LimitInternalRecursion 20
    

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

提交回复
热议问题