How to redirect url with forward slash in .htaccess?

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

How to redirect url with forward slash in .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , a month ago

@cali_green 

To redirect a URL with a forward slash in .htaccess, you can use the following code:

1
2
RewriteEngine On
RewriteRule ^old-url/$ /new-url [L,R=301]


In this code:

  • RewriteEngine On enables the rewriting engine.
  • RewriteRule ^old-url/$ /new-url [L,R=301] redirects the old URL to the new URL. The ^old-url/$ part matches the old URL with a trailing slash, and the /new-url part is the new destination URL. The L flag indicates that this is the last rule to be processed, and the R=301 flag specifies that it is a 301 (permanent) redirect.


Make sure to replace old-url and new-url with the actual URLs you want to redirect. You can add this code to your .htaccess file located in the root directory of your website.