• Resolved jdavidstark

    (@jdavidstark)


    From this closed thread, I see that I should be able to redirect a URL that contains spaces. If I try the URL with hyphens instead of spaces or %20, I can get it to work just fine. But seemingly nothing I try gets the redirect to work if the page name contains spaces.

    For additional context, I’m trying to work out the redirect with RegEx so that it will still redirect if and when additional parameters get added onto the end of the URL.

    Would you have any insight into what’s happening here?

    Thanks so much!

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author John Godley

    (@johnny5)

    There are a couple of different things going on here.

    The first is you are trying to redirect a file, and your server may be configured to prevent this:

    https://redirection.me/support/problems/url-not-redirecting/

    It is not necessary to use a regex to handle query parameters, and you can just ignore them:

    https://redirection.me/support/matching-a-url/

    Thread Starter jdavidstark

    (@jdavidstark)

    Thanks so much for your response!

    The first is you are trying to redirect a file, and your server may be configured to prevent this

    My apologies that I neglected to mention file redirection explicitly. All other file URLs redirect just fine, and if I try to redirect …/Open-Online-Library.htm, that redirects fine as well. But if I try to redirect …/Open Online Library.htm or …/Open%20Online%20Library.htm, the redirect seemingly doesn’t “take.”

    Would you have any further insights or suggestions about next steps?

    Plugin Author John Godley

    (@johnny5)

    Spaces make no difference to a redirect, and it is more likely a server configuration setting as described above.

    What is the actual redirect you have created?

    Thread Starter jdavidstark

    (@jdavidstark)

    I’ve tried several different ones, but here’s one version:

    "url": "^\/wp-content\/uploads\/file-store\/Open.Online.Library.*",
    "match_url": "regex",
    "match_data": {
    "source": {
    "flag_query": "exact",
    "flag_case": true,
    "flag_trailing": true,
    "flag_regex": true
    }
    },
    "action_code": 301,
    "action_type": "url",
    "action_data": {
    "url": "https://www.jdavidstark.com/wp-content/uploads/2024/01/Open-Online-Library.htm"
    },
    "match_type": "url",
    "title": "",
    "hits": 1,
    "regex": true,
    "group_id": 9,
    "position": 3,
    "last_access": "29 January 2024",
    "enabled": true
    • This reply was modified 9 months, 3 weeks ago by jdavidstark.
    Plugin Author John Godley

    (@johnny5)

    Do you need to use a regular expression?

    Thread Starter jdavidstark

    (@jdavidstark)

    Do you need to use a regular expression?

    No, not now that I see, from your comment above, that I can simply ignore added parameters. Here’s an updated redirect without the RegEx, but still no dice on it actually getting redirected.

    {
    "id": 262,
    "url": "/wp-content/uploads/file-store/Open Online Library.htm",
    "match_url": "/wp-content/uploads/file-store/open%20online%20library.htm",
    "match_data": {
    "source": {
    "flag_query": "pass",
    "flag_case": true,
    "flag_trailing": true,
    "flag_regex": false
    }
    },
    "action_code": 301,
    "action_type": "url",
    "action_data": {
    "url": "https://www.jdavidstark.com/wp-content/uploads/2024/01/Open Online Library.htm"
    },
    "match_type": "url",
    "title": "",
    "hits": 2,
    "regex": false,
    "group_id": 9,
    "position": 3,
    "last_access": "13 February 2024",
    "enabled": true
    }

    If, however, I make

    "url": "/wp-content/uploads/file-store/Open Online Library.htm"

    to be

    "url": "/wp-content/uploads/file-store/Open-Online-Library.htm"

    then the redirect does happen if I go to Open-Online-Library.htm. Unfortunately, it’s the URL with the spaces (not the hyphens) that I’m trying to redirect.

    Would any of this prompt any other ideas about possible options?

    Thanks, again!

    Plugin Author John Godley

    (@johnny5)

    Are you sure it’s not working? The hits above suggests it received 2 hits. You may need to clear your browser cache.

    The same redirect works fine for me.

    Thread Starter jdavidstark

    (@jdavidstark)

    Thanks. The 2 hits recorded have come from when I’ve temporarily tested whether Open-Online-Library.htm (with dashes, not spaces) will redirect successfully, and it does.

    When I swap back in either spaces or %20, however, I’m not able to get the redirect to work, even after clearing browser caches, trying different browsers, etc.

    Would you have any other suggestions about what to try next?

    Thanks again!

    Plugin Author John Godley

    (@johnny5)

    It is still more likely a problem caused by your server setup, or something else specific to your site. The above redirect works fine when I try it on my own server, and nobody else is experiencing a problem with spaces in URLs. I don’t have access to the full context, which makes it very difficult for me to suggest much else. You will need to try and narrow the problem down – try disabling other plugins, try exporting the redirect to .htaccess, try the redirect on a different server etc

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Redirecting URL with Spaces’ is closed to new replies.