2

I have some urls looking like this:

redirect 301 /some/old/url/ http://example.com/url
redirect 301 /some/old/test/ http://example.com/test

What I do want is kind of like this:

redirect 301 /some/old/[word-match-with-or-without-trailing-slash] http://example.com/[same-word-without-trailing slash]

How do I do this? The problems:

  1. Match both with or without slash.
  2. Keep the match without slash for later use (see next).
  3. Put the match witout slash at the end of the line.

Update

It seems like I could do something like this (untested):

redirect 301 /some/old/(.*) http://example.com/$1

But then how can I remove the possible trailing slash in $1?

Jens Törnell
  • 23,180
  • 45
  • 124
  • 206
  • See [`Redirect`](https://httpd.apache.org/docs/current/en/mod/mod_alias.html#redirect): "Additional path information beyond the matched URL-Path will be appended to the target URL." – Olaf Dietsche Jul 04 '16 at 07:44
  • @OlafDietsche Alright! I updated my question with an update with a possible half solution. If it's there by `$1`, how can I remove the possible ending slash to not use it in the new url? – Jens Törnell Jul 04 '16 at 07:53
  • 1
    You cannot with `Redirect`. For more elaborate modifications, you need `RedirectMatch` or even `RewriteRule`. – Olaf Dietsche Jul 04 '16 at 07:58

1 Answers1

3

To redirect to remove the trailing slash ,you can use :

RedirectMatch ^/some/old/(.*?)/?$ http://example.com/$1
Amit Verma
  • 40,709
  • 21
  • 93
  • 115