I am using wordpress, I have installed LAMP, created virtual host and migraated a website from other host consists www, but here in Digital Ocean I have failed to bring the www by all means. May be something I am missing. Please someone please guide me step by step.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
To redirect a non-www domain name to a www domain in a WordPress setup on a LAMP stack, you’d typically make modifications to the Apache configuration or to the .htaccess file within your WordPress directory.
I’ll recommend adding the 301 Redirect in your .htaccess file rather than in the Apache configuration.
Backup: Before making any changes, it’s always a good practice to backup your current .htaccess file.
Access .htaccess File: Navigate to the root directory of your WordPress installation, where you should find the .htaccess file.
cd /path/to/your/wordpress/directory
Open the .htaccess file
sudo nano .htaccess
.htaccess file, add the following lines:RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Replace example.com with your domain name.
service apache2 restart
Settings > General.www.Hello @mushfiq
The DNS seems sorted, so the only thing left to do is to handle the redirect itself. In Apache, this mostly happens in the .htaccess file, but you also need to ensure that Mod Rewrite is enabled.
First, to enable the mod_rewrite module you need this command:
- sudo a2enmod rewrite
With the Rewrite module enabled, we can configure Apache with redirect rules using .htaccess files.
You can use the .htaccess file rule provided by KFSys.
Hope that this helps
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.