Remove multiple /// in url

What is the name of the domain?

What is the issue you’re encountering

I’m trying to make a rule to remove multiple /// in uri

What steps have you taken to resolve the issue?

I’ve try to create a redirect rule using wildcard pattern:
rule: https://statbet.com/*//*
action: https://statbet.com/${1}/${2}
status code: 301

the goal is to make a redirect from
https://statbet.com/dsds///cdcdc/dcdcdc/ccd////ccd to https://statbet.com/dsds/cdcdc/dcdcdc/ccd/ccd

they idea was to split url to 2 parts - before // and after //, and then concat part1+/+part2, changing // to /
it would create multiple redirects, but in the end user will be on a correct page.

But this is not working, and can’t find out why.

Mind if I ask how this happened that you’ve got multiple trailing/end slashes in between? :thinking: Is it crawled and indexed like that as well?

Might have to escape those as well in your Rule :thinking:

How’s your URL Normalization configured at Cloudflare dashboard?

It’s a request from SEO people to make a behavior like that. There are no generated links that match that pattern, but as far I understand there are some typos in inbound links.

And for Google a/a different from a//a that’s why we were asked to make 301 redirects, that cover all possible links with multiple slashes.

Unfortunately there is no way to handle such a case from framework side, and I got an idea to make those redirects on Cloudflare (because previous requests, like lowercase all URLs were successfully done by redirection rules)

I’ve already added Cloudflare normalization, which should remove // according to doc:

  1. Merge successive forward slashes (for example, // will be normalized to /).

but it seems that it’s not working

https://statbet.com/football/teams/manchester-city-fc////results => 404 instead of 301 to https://statbet.com/football/teams/manchester-city-fc/results

You need to enable “Normalize URLs to origin” as well.

Note that normalization does not redirect, it just rewrites the request passing through Cloudflare.

1 Like

Yep, seems that normalization can’t help. It should be done by redirection rule to get 301 redirect. There is a regexp support on Business+ plans, but free and pro plans are limited to wildcard replace, which seems to be not working with //


this was my initial idea, but its not working. It seems that urls with multiple // are not matched

Ok, disabling Cloudflare normalization helps. It works now (within multiple redirects, but works).

1 Like

To remove multiple slashes (//) in the URI and redirect to the correct URL, use the following approach:

Solution:

  1. Regular Expression for Redirect: Use this regex pattern to match multiple slashes:

regex

CopyEdit

^(.*)\/+(.+)$
  1. Server-Specific Rules:
  • Apache (.htaccess):

apache

CopyEdit

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule ^(.*)//(.*)$ https://statbet.com/$1/$2 [R=301,L]
  • Nginx:

nginx

CopyEdit

server {
    location ~* ^(.*)//(.*)$ {
        return 301 https://statbet.com/$1/$2;
    }
}
  1. Test: Redirect from:

ruby

CopyEdit

https://statbet.com/dsds///cdcdc/dcdcdc/ccd////ccd

To:

ruby

CopyEdit

https://statbet.com/dsds/cdcdc/dcdcdc/ccd/ccd

This should cleanly redirect URLs with multiple slashes to a single slash.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.