WordPress.org

Ready to get started?Download WordPress

Forums

Redirection
Regex redirect without adding rest of URL (4 posts)

  1. autumnmist
    Member
    Posted 2 years ago #

    Is there any way to redirect all requests to a particular regex to a single URL, but *without* adding the rest of the matched regex to the target URL?

    I want http://mysite/pdfs/* to redirect to http://newsite/

    Right now if I enter the target URL as http://newsite/ as someone tries to access http://mysite/pdfs/mydoc.pdf they get redirected to http://newsite/mydoc.pdf but I just want them to end up on the landing page at http://newsite

    http://wordpress.org/extend/plugins/redirection/

  2. Workshopshed
    Member
    Posted 2 years ago #

    Try the following as the source URL

    /pdfs/(.*)

    and then the destination as

    http://newsite/

    don't forget to tick the box that says "regular expression". The brackets are what is known as a capture group in regular expressions, if you don't include a $1 then it will simply throw away everything that matches the expression in the brackets

  3. autumnmist
    Member
    Posted 2 years ago #

    Oh, yeah, I forgot to mention that I tried that as well. (I'm a Perl programmer so I'm familiar with regexes). If I try /pdfs/(.*) and the destination http://newsite/, the entire redirect just fails to trigger and I get a 404 page.

  4. autumnmist
    Member
    Posted 2 years ago #

    Ah hah! I just got it working.

    If I tried to make the edits to the old (existing) redirection entry, the redirect would fail. If I completely delete the old entry and recreate a new one with the same settings, the redirect works!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic