How to redirect /post-name to /post/post-name?

by mallory_cormier , in category: Third Party Scripts , a month ago

How to redirect /post-name to /post/post-name?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , a month ago

@mallory_cormier 

You can redirect the URL /post-name to /post/post-name by adding a RewriteRule in the .htaccess file of your website. Here's an example of how you can do this:

  1. Open the .htaccess file in the root directory of your website using a text editor.
  2. Add the following line of code to create the redirect:
1
2
RewriteEngine On
RewriteRule ^post-name$ /post/post-name [R=301,L]


  1. Save the .htaccess file and upload it back to your server.


With this rule in place, any requests for /post-name will be redirected to /post/post-name. The 301 status code indicates that this is a permanent redirect, which can be beneficial for search engine optimization to ensure that the new URL is properly indexed.