To set up WordPress in a subdirectory (e.g., acmecorp.com/blog
) while keeping your main Angular SPA website at the root domain (acmecorp.com
), follow these steps:
1. Backup Your Current Website and Database:
Always ensure you have complete backups of both your website files and your database before making significant changes.
2. Install WordPress in a Subdirectory:
-
Create a subdirectory: In your website's root folder (where your Angular app resides), create a new folder called
blog
. -
Upload WordPress: Download the latest version of WordPress from the official website. Unzip it and upload all its files to the
blog
folder using FTP or any other file management tool you prefer. -
Install WordPress: Access the WordPress setup by visiting
acmecorp.com/blog/wp-admin/install.php
and follow the on-screen prompts to set up WordPress.
3. Adjust WordPress Settings:
-
Change the site address: Once you have installed WordPress, log in to the admin dashboard. Go to
Settings
>General
.- WordPress Address (URL):
https://acmecorp.com/blog
- Site Address (URL):
https://acmecorp.com/blog
Save the changes.
- WordPress Address (URL):
4. Update Your Angular SPA Configuration:
You may need to ensure that any routing in your Angular app doesn't conflict with the /blog
endpoint.
-
Update
.htaccess
for Angular: If you're using an.htaccess
file for your Angular app to handle routing, make sure it allows the/blog
endpoint to be processed by WordPress. An example.htaccess
that integrates both the Angular app and WordPress might look like this:RewriteEngine On # For the Angular App RewriteCond %{REQUEST_URI} !^/blog RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] # Let WordPress handle its endpoints RewriteCond %{REQUEST_URI} ^/blog RewriteRule ^blog/(.*)$ /blog/index.php [L]
5. Migrate Content from the Subdomain:
If you have existing content on blog.acmecorp.com
, you'll need to migrate it.
-
Export content from the old blog: On
blog.acmecorp.com
, go toTools
>Export
in the WordPress dashboard to download an XML file of all your content. -
Import content to the new blog: On
acmecorp.com/blog
, go toTools
>Import
, install the WordPress importer if prompted, then upload the XML file you just downloaded.
6. Redirects:
To maintain SEO rankings and ensure that visitors accessing the old blog URLs get redirected to the new location, you should set up 301 redirects from blog.acmecorp.com
to acmecorp.com/blog
.
-
Using .htaccess: If both sites are on the same server, and you're using Apache, you can set up a
.htaccess
redirect like this:RewriteEngine on RewriteCond %{HTTP_HOST} ^blog\.acmecorp\.com$ RewriteRule ^(.*)$ https://acmecorp.com/blog/$1 [R=301,L]
-
Using a WordPress Plugin: If you prefer, you can use plugins like "Redirection" on the old
blog.acmecorp.com
site to manage the redirects.
Lastly, don't forget to update any internal or external links pointing to blog.acmecorp.com
to reflect the new URL structure, and monitor for any 404 errors to ensure a smooth transition.