How to 301 redirect with or without the trailing slash?

14,272

You want the expression to see the / as optional

^login/?$

The ? token will allow for the zero or one occurence of the /

Share:
14,272
Cris
Author by

Cris

Updated on July 28, 2022

Comments

  • Cris
    Cris over 1 year

    I want to redirect site.com/login OR site.com/login/ to site.com/wp-login.php

    Here's what I have so far:

    RewriteRule ^login$ "\/wp\-login\.php" [R=301,L]
    

    But it doesn't redirect /login/ (with the trailing slash). How to tell htaccess to redirect with or without the trailing slash?

    Thank you, Cris