How to redirect url with forward slash in .htaccess?

by cali_green , in category: Third Party Scripts , 6 months ago

How to redirect url with forward slash in .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , 6 months 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.

Related Threads:

How to allow only 1 forward slash in regex expression?
How to redirect url in .htaccess?
How to redirect to a specific url in htaccess?
How to redirect url via .htaccess?
How to redirect website url to https:// using .htaccess file?
How to use .htaccess to redirect while maintaining the original url?