norman.lol
norman.lol

Reputation: 5374

How to rewrite .htaccess rule to URL minus one character?

A Newsletter was send with a token generated login URL inside. Accidentally a closing square bracket ] was placed as the URL's last character and the login links now doesn't work. How to redirect any URL with a closing square bracket to the same URL without the square bracket?

Upvotes: 1

Views: 195

Answers (2)

Jon Lin
Jon Lin

Reputation: 143906

You can either use mod_alias and the RedirectMatch directive or mod_rewrite and the RewriteRule directive. If you already are using mod_rewrite elsewhere, it may be more prudent to stick with mod_rewrite, otherwise it doesn't matter:

RedirectMatch 301 ^/(.*)\]$ /$1 

or

RewriteEngine On
RewriteRule ^(.*)\]$ /$1 [L,R=301]

Upvotes: 1

anubhava
anubhava

Reputation: 785471

You can use this rule:

RewriteEngine On

RewriteRule ^(.+?)]$ /$1 [R=301,L,NE]

Upvotes: 0

Related Questions