Reputation: 96
Can anyone please point me to a tutorial or article or give a solution (with some explanation) on how to redirect one level up if certain string exists at the end of the URL.
For example
http://www.example.com/s/texas/hello-world/
should be redirected to
http://www.example.com/s/texas/
Assume the string is 'hello-world' and I have 100 different urls
i.e /s/florida/hello-world
/c/boston/massachusetts/hello-world etc.
Thanks in advance.
Upvotes: 2
Views: 282
Reputation: 270637
The expression below captures everything before hello-world
inside (.*)
as $1
and redirects to it. The /?
makes the trailing slash optional.
RewriteEngine On
RewriteRule ^(.*)hello-world/?$ $1 [L,R=301,QSA]
Upvotes: 1