Where to add redirect rules?

My YunoHost server

Hardware: Old laptop or computer
YunoHost version: 3.7.1.1
I have access to my server : Through SSH and webadmin. I also have direct access to the server if needed.
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

Description of my issue

I recently moved my WordPress installation from a shared host to my own YunoHost server. In the process, I changed the site URL from example.com/blog to blog.example.com. I have updated the WordPress settings to recognize this as a new location; however, there are still many links elsewhere on the internet that point to example.com/blog.

I’d like to create a URL redirect rule that sends traffic from example.com/blog/foobar to blog.example.com/foobar. How do I do that with YunoHost?

Thanks. :slight_smile:

Hmm, in SEO terms the opposite is better (shift from subdomain to subdirectory).
If you really want to do it, I can suggest a tuto I did 4 years ago and that should still be up to date.
The translation should also work.

Maybe you’re looking for the redirect app : https://github.com/YunoHost-Apps/redirect_ynh

Thank you both for your responses. I tried the redirect app, but I have a Custom Webapp at the root of https://example.com/ and so can’t put a redirect on that domain.

I’ve seen the recommendation to use .htaccess files, and this seems promising. My understanding is that .htaccess files are typically used by Apache. Does YunoHost use Apache or nginx, and if the latter, how can I do something similar with nginx?

Under /etc/nginx/conf.d/example.com.d/redirect.conf and add:

location / {


    return 301 $scheme://blog.example.com$request_uri;


}

This looks very promising.

I don’t want to redirect everything from example.com, only from example.com/blog/. Would that look like this?

location /blog {

    return 301 $scheme://blog.example.com$request_uri;

}

Or is there some other way to do that?

Edit: This did the trick! It redirects to blog.example.com/blog/foobar, but then a redirection WordPress plugin on my WordPress site strips out the /blog/.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.