.htaccess - RewriteCond and RewriteRule to do a permanent redirect to https://www. and keep the query string -
i using mod_rewrite condition/rule shown below redirect url www equivalent , ensure https.
rewritecond %{http_host} ^example.com [nc] rewriterule ^(.*)$ https://www.example.com/$1 [l,r=301,nc]
this, example, converts example.com/foo/bar
https://www.example.com/foo/bar
, works fine. however, if link includes query string (eg, http://example.com/foo/bar?x=baz&y=qux
), query string not appended. how can modify rewritecond/rewriterule above http://example.com/foo/bar?x=baz&y=qux
automatically converted https://www.example.com/foo/bar?x=baz&y=qux
query string appended? have tried adding qsa (query string append) flag in rewrite rule , doesn't help.
you need qsa flag (query string append)
rewritecond %{http_host} ^example.com [nc] rewriterule ^(.*)$ https://www.example.com/$1 [l,r=301,nc,qsa]
second option
rewriterule ^(.*)$ https://www.example.com/$1?%{query_string} [l,r=301,nc]
Comments
Post a Comment