.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

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -