RewriteRule that preserves GET parameters

后端 未结 3 1450
-上瘾入骨i
-上瘾入骨i 2020-11-30 13:14

What is wrong with this rewrite rule?

RewriteRule ^api/(.+)$ api/index.php?url=$1 [L]

I simply want \"index.php?url=\" to be added after ap

相关标签:
3条回答
  • 2020-11-30 13:30

    Are you doing something to stop infinite recursion?

     RewriteRule ^api/(.+)$ api/index.php?url=$1 [R=301,L]
    

    or some equivalent

    0 讨论(0)
  • 2020-11-30 13:31

    I think you must write your domain name before the regex stuff. Like this:

    RewriteRule ^(.+).com/api/(.*)$ "$1.com/api/index.php?url=$2" [R=301,L]
    
    0 讨论(0)
  • 2020-11-30 13:39

    The regex on the RewriteRule is only run against the path part of the URL, not the query parameters. Fortunately there is the [QSA] flag to preserve existing query parameters.

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