How to Redirect Non WWW Website to WWW Version on

2019-09-15 05:12发布

问题:

I have hosted my Website on Digital Ocean & Installed Wordpress through Serverpilot. Current Home Page URL is www.xyz.com & xyz.com is also redirecting on it.

But When I open xyz.com/test-post its not rediecting on www.xyz.com/test-post. How can I Redirect it ?

回答1:

Set the www version of URL in WordPress Address (URL) and Site Address (URL) fields present under WordPress (backend)

and then write this in your .htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

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

Hope this help you.