0

I am retiring a site and would like to display a message when anyone tries to access any page on the site EXCEPT for a couple of pages. Some pages have certain pageid parameters. So basically everything should redirect to /retired except for:

  • /testcode.jsp

  • /search/*

  • /codes/*

  • /resources/blogs/*

  • /status/*

  • /wiki/article?pageid=178973-ghgh-98089

  • /wiki/article?pageid=354973-aaaa-80879

  • /wiki/article?pageid=334224-sada-20293

  • /wiki/article?pageid=546665-qasq-34491

MrWhite
  • 11,643
  • 4
  • 25
  • 40
Hansilog
  • 11
  • 1
  • 3
  • Are you intending to use `.htaccess`? Or is this all in the server config? Do you have any existing directives? How you implement this can be dependent on your existing directives. For instance, are some of these URLs routed through afront-controller? I'd also question why you want to "redirect" to `/retired`, rather than serve a custom 404/410, since presumably you want to remove these pages from the index if the site is being "retired"? – MrWhite Apr 02 '18 at 19:51
  • @MrWhite ... It will be in server config, straight-forward config. The site as a whole will be redirected to /retired and will have custom message, except for some pages, static (html/jpg/js) and dynamic(served by an app server --- those wiki and /resources/blogs, /codes, /search and /status pages). – Hansilog Apr 02 '18 at 23:10

1 Answers1

0

Looks like you want to make use of Apache's RewriteCond directive to conditionally redirect requests based on a pattern match, like so:

RewriteCond "%{REQUEST_URI}" "! /testcode.jsp" [OR]
RewriteCond "%{REQUEST_URI}" "! /search/*" [OR]
{ditto for your other requirements...}
RewriteRule .* /retired [R,L]

Which should explicitly allow anything in your regex pattern through, while redirecting everything else. See also, https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond For more details.

Thomas N
  • 436
  • 2
  • 9
  • For me the CondPattern "! /testcode.jsp" did not work with the quotes. I had to remove the quotes to make it work. Otherwhise EVERYTHING matched. no idea why... – Daywalker Mar 18 '21 at 13:09