Rewriting query string using mod_rewrite

后端 未结 2 644
南旧
南旧 2020-12-18 11:57

In my MVC application I use a uri router than determines which controller and action to use and detects GET parameters from the uri. I\'ve written it so that it will accept

相关标签:
2条回答
  • 2020-12-18 12:42

    If you really want to redirect requests of the form /controller/action?param1Name=param1Value to /controller/action/param1Name/param1Value, try this:

    RewriteCond %{THE_REQUEST} ^GET\ /[^/]+/[^/]+\?[^\s]+
    RewriteCond %{QUERY_STRING} ^([^=&]+)=([^&]+)&?(.*)
    RewriteRule ^[^/]+/[^/]+.* /$0/%1/%2?%3 [N]
    RewriteCond %{THE_REQUEST} ^GET\ /[^/]+/[^/]+\?[^\s]+
    RewriteRule ^[^/]+/[^/]+.* /$0 [L,R=301]
    

    But if you want to opposite way:

    RewriteRule ^([^/]+/[^/]+)/([^/]+)/([^/]+)(/.*) $1$4?$2=$3 [QSA]
    
    0 讨论(0)
  • 2020-12-18 12:45

    If you're doing it for cosmetic reasons you may want to do a POST instead, and then the query params will not be shown in the URL.

    If not - I'd like to see the answer to this one myself!

    0 讨论(0)
提交回复
热议问题