2
Redirect 302 "/blog" /

I would expect this rule to take requests from /blog to / and /blog/stuff to /; instead of /blog/stuff to //stuff

The behavior of going from /blog/stuff to //stuff is what I would expect from an unclosed regex

what is going on? I thought Redirect was supposed to redirect to a different URL, not substitute the match with the target string.

Why doesn't one directive do one thing?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
ahnbizcad
  • 10,491
  • 9
  • 59
  • 85

1 Answers1

1

The quote marks do not work as you expect them, in the Redirect directive. For the syntax:

Redirect [status] [URL-path] URL

[...]
Then any request beginning with URL-Path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-Path will be appended to the target URL.

You're probably looking for the RedirectMatch directive instead.

RedirectMatch 302 /blog.* /

The quoted pattern/path is just a syntactic sugar, available to enclose paths containing (spaces).

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • doesn't redirect match take regex as the request argument? – ahnbizcad Sep 14 '16 at 07:51
  • @ahnbizcad Yes, it does. Which is why it'll replace everything `/blog....` with just `/` – hjpotter92 Sep 14 '16 at 08:18
  • I want it to trigger on `/blog` only. If it has stuff after `/blog`, I don't want it to trigger. And I don't want it to replace, I want it to just go to that relative URL. So would `RedirectMatch 302 ^/blog$` work? I was pretty sure it wasn't working when I tested. Maybe I'm wrong. – ahnbizcad Sep 14 '16 at 08:38
  • @ahnbizcad Perhaps try a pattern like `^/blog/?$` – hjpotter92 Sep 14 '16 at 08:52