My wordspress site is installed in myfolder and it auto create the code in htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myfolder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myfolder/index.php [L]
# END WordPress

Now I would like to force www to all my links and find this code:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

If I put them together it won't work.. Can anyone help me?

Thank you~~~

1 Answer 1


Place this above the # BEGIN WordPress line.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]
  • Thank you. But seems not working. example.com/myfolder will become example.com
    – goomember
    May 4, 2017 at 16:37
  • The %1 and $1 are variables that preserve /myfolder. Did you try checking the actual HTTP headers with a tool like Webconfs? If you are just trying in your web browser you may be cached, making it look like the changes didn't work when they actually did. Or, your host may have a server-side cache that needs to be cleared.
    – WebElaine
    May 4, 2017 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.