I have Wordpress on nginx that serves blogposts from www.helenagwyn.com/blog/... . I want to move my blog to helenagwyn.blog/... . The rest of the pages will remain on helenagwyn.com. Is there a way to automatically redirect a request for helenagwyn.com/blog/... to helenagwyn.blog/... ?
Redirect Wordpressblog on Nginx
- Edited
HelenaGwyn we've got some redirection features on the todo list, but for now you can do it by setting up a separate app to serve the redirect.
Here's how:
- Go to https://my.opalstack.com/apps/ and click "Create Application".
- Enter an app name like "helenagwyn_blog_redirect" (ignore the placeholder text that reads "username", we'll have that fixed soon).
- Select "PHP-CGI with Apache" as the app type (so we can use
.htaccess
later). - Select the shell user that currently serves the apps on helenagwyn.com.
- Click the "Create Application" button and wait a few seconds for the app to be created.
- Create a file
/home/shelluser/apps/helenagwyn_blog_redirect/.htaccess
(replaceshelluser
with the following contents:
RewriteEngine on RewriteRule ^(.*)$ https://helenagwyn.blog/$1 [R=301,L]
- Go to https://my.opalstack.com/domains/ and click the edit icon for your site.
- Click the purple "Route Application" button.
- Select your "helenagwyn_blog_redirect" app from the list.
- Enter
/blog
in the field next to the selected application. - Click the green "Update site" button to save your changes.
Your redirect should begin working a few seconds after you complete those steps.
Hope this helps
Apparently I was mistaken. The blogposts are served from the root as in "helenagwyn.com/2021/06/06/title". Do I create applications for each year? Or is the best and other solution to turn the app in a PHP-CGI with Apache so I can serve the .htaccess for the root?
- Edited
HelenaGwyn you shouldn't need to create a separate app for each year.
The ^(.*)$
means "match the entire URI path", meaning the part after the domain.
The $1
inserts that matched value into the destination URL for the redirect.
If the original blog at helenagwyn.com/blog/ used the same permalink format then the redirect that you have ought to be working.
Feel free to contact support via email if you need us to take a closer look. Thanks!
For future reference I wanted to share I used the plugin https://wordpress.org/plugins/redirection/ with the following rules:
Redirect catgories
^/category/(.*)$
tohttps://helenagwyn.blog/categorie/$1
Redirect blogposts
^(\/[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/.*)$
to https://helenagwyn.blog/$1