.htaccess remove query string, keeping SEO style url

前端 未结 1 375
有刺的猬
有刺的猬 2020-12-21 18:51

Question:

Is it possible to clear the %{QUERY_STRING} without breaking any functionality of what I\'ve accomplished in my .htaccess fil

相关标签:
1条回答
  • 2020-12-21 19:26

    Try:

    RewriteCond %{THE_REQUEST} \?[^\ ]+
    RewriteRule (.*) /$1? [R=301,L] #remove query string
    

    You need to match against the actual request because you're building a query string with these rules:

    # To internally rewrite directories as query string
    RewriteRule ^([^/=]+)=([^/]*)(/(.+))?\/?$ /$4?$1=$2 [N,QSA]
    RewriteRule ^([^/=]+)/([^/=]+)(/(.+))?\/?$ /$4?$1=$2 [N,QSA]
    RewriteRule ^([^/=]+)(/(.+))?\/?$ /$3?$1 [N,QSA]
    

    When these rules loop around, the %{QUERY_STRING} variable will have stuff in it and your rules will clobber them. If you match against the actual request, your rewrites won't get affected.

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