Expand my Community achievements bar.

SOLVED

Double Slash (//) Issue in URLs Despite Applied Rewrite Rules

Avatar

Level 2

Hi,

We are experiencing a persistent double-slash (//) issue in our website URLs, which are also getting indexed by Google. An example of the problematic URL is -: https://mywebsite.com//content/site/en/learn/about-us/company-overview.html

 

We have applied the following Rewrite Rules in our dispatcher

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule ^ %1/%2 [R=301,L]

RewriteRule ^/$ /content/site/en.html [R=301]
RewriteRule ^/en(.*)$ /content/site/en$1 [R=301]
RewriteRule ^/content/site/en$ /content/site/en.html [R=301,L]

 

Additionally, we also tried the following alternative rules:-

RewriteCond %{REQUEST_URI} ^//+
RewriteRule ^(//+)(.*)$ /$2 [R=301,L]

 

RewriteCond %{REQUEST_URI} ^//content/site/en(.*)$
RewriteRule . /content/site/en$1 [R=301,L]

 

 

Despite these rules, we still see URLs with double slashes getting generated and indexed. These are also appearing in the Google Search Console under the list of crawled URLs.

 

Are there any potential issues with the above rules that could allow double slashes to persist or Is there any configuration in Sling Mappings, Dispatcher Settings, or AEM Resource Resolver that could be conflicting with these rules?

Any guidance to resolve this would be appreciated. Thanks in advance!

 

@arunpatidar   @SantoshSai

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @rajesh_didshe ,

Try below solution:

1. Fix Link Generation in AEM Code

Double slashes are often introduced due to bad string concatenation like:

String link = page.getPath() + "/" + resource.getName();

If page.getPath() ends with / and resource.getName() starts with /, you get //.

Use Apache Commons or Manual Clean:

link = (page.getPath() + "/" + resource.getName()).replaceAll("/{2,}", "/");

Or in HTL (Sightly):

<a href="${path @ context='uri'}"></a>

Don't manually concatenate URLs — always use AEM’s URL helpers or sanitization.

 

2. Fix /etc/map or /conf/global/settings/rewrites Mappings

If you're using Apache Sling Resource Resolver mappings, misconfigured rules can inject double slashes.

Check paths like:

  - /etc/map/http

  - /conf/global/settings/rewrites

Fix mappings like this:

/content/site/en -> /

And ensure the mapping doesn’t end with a slash if your site code is also adding one.

 

3. Hard Redirect Fix in Dispatcher (Apache HTTPD)

This helps ensure SEO does not persist on old bad URLs:

Add this powerful rewrite to eliminate all double slashes:

RewriteCond %{THE_REQUEST} //+
RewriteRule .* %{REQUEST_URI} [R=301,L,NE,E=fix_double_slash:1]

# Canonical rewrite - collapse double slashes
RewriteCond %{REQUEST_URI} ^(.*)//+(.*)$
RewriteRule .* %1/%2 [R=301,L]

This ensures only single-slash URLs reach AEM, and browsers/SEO agents get 301 redirects.

 

4. Remove Already Indexed Bad URLs

Even after fixing generation and redirects, Google Search Console will still show previously indexed bad URLs.

Steps:

  - Go to Google Search Console => Removals

  - Click “New Request” => Temporary Removal

  - Add URLs like:

https://mywebsite.com//content/site/en/*

  - Resubmit clean sitemap with only good URLs.

Regards,
Amit

View solution in original post

2 Replies

Avatar

Level 9

hi @rajesh_didshe If the double slashes are being generated from AEM code, the rewrite rules will only help with requests, not with link generation. Meaning that an incorrect URL with a double slash will be present within the page content, hence SEO will index them. The rewrite rule will help you to get a working page instead of a 404 but the goal should be to have correct formatted URL in the content.

 

If you have custom mappings in /etc/map or /conf/global/settings/, review them for any that could introduce double slashes.

Double slashes are often introduced by concatenating paths in code (for example using domain/page.path/child.path) without trimming. Review your HTL, JSP, or backend code for concatenation errors.

Once you have identified the root cause, you can leverage the URL Removal Tool in Google Search Console to remove double-slash URLs and then submit an updated sitemap without double-slash URLs.

Avatar

Correct answer by
Community Advisor

Hi @rajesh_didshe ,

Try below solution:

1. Fix Link Generation in AEM Code

Double slashes are often introduced due to bad string concatenation like:

String link = page.getPath() + "/" + resource.getName();

If page.getPath() ends with / and resource.getName() starts with /, you get //.

Use Apache Commons or Manual Clean:

link = (page.getPath() + "/" + resource.getName()).replaceAll("/{2,}", "/");

Or in HTL (Sightly):

<a href="${path @ context='uri'}"></a>

Don't manually concatenate URLs — always use AEM’s URL helpers or sanitization.

 

2. Fix /etc/map or /conf/global/settings/rewrites Mappings

If you're using Apache Sling Resource Resolver mappings, misconfigured rules can inject double slashes.

Check paths like:

  - /etc/map/http

  - /conf/global/settings/rewrites

Fix mappings like this:

/content/site/en -> /

And ensure the mapping doesn’t end with a slash if your site code is also adding one.

 

3. Hard Redirect Fix in Dispatcher (Apache HTTPD)

This helps ensure SEO does not persist on old bad URLs:

Add this powerful rewrite to eliminate all double slashes:

RewriteCond %{THE_REQUEST} //+
RewriteRule .* %{REQUEST_URI} [R=301,L,NE,E=fix_double_slash:1]

# Canonical rewrite - collapse double slashes
RewriteCond %{REQUEST_URI} ^(.*)//+(.*)$
RewriteRule .* %1/%2 [R=301,L]

This ensures only single-slash URLs reach AEM, and browsers/SEO agents get 301 redirects.

 

4. Remove Already Indexed Bad URLs

Even after fixing generation and redirects, Google Search Console will still show previously indexed bad URLs.

Steps:

  - Go to Google Search Console => Removals

  - Click “New Request” => Temporary Removal

  - Add URLs like:

https://mywebsite.com//content/site/en/*

  - Resubmit clean sitemap with only good URLs.

Regards,
Amit