AEM 6.3: Getting 403 error on dispatcher and blank page | Community
Skip to main content
Level 4
March 10, 2018
Solved

AEM 6.3: Getting 403 error on dispatcher and blank page

  • March 10, 2018
  • 19 replies
  • 14903 views

Hi,

I have configured Apache web server and dispatcher. Here are the rewrite rules:

RewriteRule ^/$ /content/aemsite/en.html [PT,L]

  RewriteCond %{REQUEST_URI} ^/content
  RewriteCond %{REQUEST_URI} !^/content/campaigns
  RewriteCond %{REQUEST_URI} !^/content/dam 
  RewriteRule !^/content/aemsite/en - [R=404,L,NC]

  RewriteCond %{REQUEST_URI} !^/apps
  RewriteCond %{REQUEST_URI} !^/content
  RewriteCond %{REQUEST_URI} !^/etc
  RewriteCond %{REQUEST_URI} !^/home
  RewriteCond %{REQUEST_URI} !^/libs
  RewriteCond %{REQUEST_URI} !^/tmp
  RewriteCond %{REQUEST_URI} !^/var
  RewriteRule ^/(.*)$ /content/aemsite/en/$1 [PT,L]

I have also configured sling mappings:

{
  "jcr:primaryType": "sling:Mapping",
  "www_aemsite_com": {
  "sling:internalRedirect": [
  "/content/aemsite/en.html"
  ],
  "jcr:primaryType": "sling:Mapping",
  "sling:match": "www.aemsite.com/$"
  },
  "www.aemsite.com": {
  "sling:internalRedirect": [
  "/content/aemsite/en",
  "/"
  ],
  "jcr:primaryType": "sling:Mapping"
  }
}

and I have also configured "Day CQ Link Checker Transformer" to strip HTML extension:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
  jcr:primaryType="sling:OsgiConfig"
  linkcheckertransformer.strictExtensionCheck="{Boolean}false"
  linkcheckertransformer.rewriteElements="[a:href,area:href,form:action]"
  linkcheckertransformer.disableRewriting="{Boolean}false"
  linkcheckertransformer.disableChecking="{Boolean}false"
  linkcheckertransformer.stripHtmltExtension="{Boolean}true"
  linkcheckertransformer.mapCacheSize="{Long}5000"/>

A trailing slash gets appended to the URL. For example, a link that points to http://www.aemsite.com/articles has the "/" appended and  I see a blank page. In the logs I see a 403 on web server level while trying to access the pages under http://www.aemsite.com/ as shown below.

127.0.0.1 - - [09/Mar/2018:22:26:44 -0500] "GET /articles HTTP/1.1" 302

127.0.0.1 - - [09/Mar/2018:22:26:44 -0500] "GET /articles/ HTTP/1.1" 403 1

How can I make sure that http://www.aemsite.com/articles gets redirected to http://www.aemsite.com/articles.html internally?

Thanks in advance

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

Hi,

for me it looks like that the problem in this case is in the webserver/dispatcher config. Is this request sent to AEM at all? If you enable debug logging on the dispatcher you can see if this request is handled by the dispatcher at all or maybe only by the webserver. And if it's handled by the dispatcher it can show you if the request is sent to AEM.

Jörg

19 replies

Level 4
March 17, 2018

The logging was already enabled for mod_rewrite but it was somehow not able to log anything. I fixed that issue and put the rules you had provided in place. What happening was that /articles/  would get converted to /articles/.html due to the /articles being turned to /articles/. So, I modified the rules a bit :

# Define virtual host for aemsite.com

<VirtualHost *:80>

  ServerAdmin webmaster@localhost

  ServerName aemsite.com

  DocumentRoot "C:\Apache2.2\htdocs"

  DirectorySlash Off

   RewriteEngine On

   RewriteLog "C:\Apache2.2\logs\rewrite.log"

   RewriteLogLevel 9

  

   RewriteRule ^/$ /content/aemsite/en.html [PT,L]

   RewriteCond %{REQUEST_URI} !^/apps

   RewriteCond %{REQUEST_URI} !^/content

   RewriteCond %{REQUEST_URI} !^/etc

   RewriteCond %{REQUEST_URI} !^/home

   RewriteCond %{REQUEST_URI} !^/libs

   RewriteCond %{REQUEST_URI} !^/tmp

   RewriteCond %{REQUEST_URI} !^/var

   RewriteCond %{REQUEST_URI} !(.*)/$

   RewriteRule ^/(.*)$ /content/aemsite/en/$1.html [PT,L]

 

</VirtualHost>

(The last two lines), thinking that the request /products would be rewritten to  /content/aemsite/en/$1.html

Here is the complete log from rewrite.log:

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (2) init rewrite engine with requested uri /products

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (3) applying pattern '^/$' to uri '/products'

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (3) applying pattern '^/(.*)$' to uri '/products'

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!^/apps' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!^/content' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!^/etc' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!^/home' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!^/libs' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!^/tmp' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!^/var' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (4) RewriteCond: input='/products' pattern='!(.*)/$' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (2) rewrite '/products' -> '/content/aemsite/en/products.html'

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353f0f8/initial] (2) forcing '/content/aemsite/en/products.html' to get passed through to next API URI-to-filename handler

-----

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (2) init rewrite engine with requested uri /products/

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (3) applying pattern '^/$' to uri '/products/'

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (3) applying pattern '^/(.*)$' to uri '/products/'

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!^/apps' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!^/content' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!^/etc' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!^/home' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!^/libs' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!^/tmp' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!^/var' => matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (4) RewriteCond: input='/products/' pattern='!(.*)/$' => not-matched

127.0.0.1 - - [16/Mar/2018:23:52:08 --0400] [aemsite.com/sid#304ab50][rid#353b0e8/initial] (1) pass through /products/

It looks like there are two requests /products and /products/, the rule works fine as long as it is /products but once it is /products/ it fails. I checked the network tab in the browser to check the requests and below is the screenshot:

I don't know what exactly is the reason behind the /products/

Thank you again for all the help and effort.

joerghoh
Adobe Employee
Adobe Employee
March 19, 2018

Strange. In your first log we see a rewrite from /products to /content/aemsite/en/products.html, but in the request view we also see a request to /products, which results in a redirect to /products/.

Have you made the changes on all dispatcher instances of the environment you were testing with?

Jörg

Level 4
March 19, 2018

I am using only one dispatcher. Are there any other logs I need to check ?

Thanks

joerghoh
Adobe Employee
Adobe Employee
March 19, 2018

This rule prevents /products/ from being rewritten:

   RewriteCond %{REQUEST_URI} !(.*)/$

But I cannot a clean picture from it.

1) Your screenshot of the browser suggests that /products is redirected to /products/

2) You posted a log extract, which shows that /products is being rewritten to /content/aemsite/en/products.html

3) You posted a log extract, which indicates, that /products/ cannot be handled.

So 1 and 2 contradict. And 3 supports the behaviour you are analyzing.

Can you validate and confirm my 3 statements here?

Jörg

Level 4
March 20, 2018

The problem is even if I comment out all the rules the /products still somehow gets converted to /products/

1) Your screenshot of the browser suggests that /products is redirected to /products/ That is correct

2) You posted a log extract, which shows that /products is being rewritten to /content/aemsite/en/products.html

3) You posted a log extract, which indicates, that /products/ cannot be handled.

I have been trying a lot of rules to make it work. The log extract must have been due to that. Sorry for the confusion, the current set of rules look like this:

RewriteRule ^/$ /content/aemsite/en.html [PT,L]

   RewriteCond %{REQUEST_URI} !^/apps

   RewriteCond %{REQUEST_URI} !^/content

   RewriteCond %{REQUEST_URI} !^/etc

   RewriteCond %{REQUEST_URI} !^/home

   RewriteCond %{REQUEST_URI} !^/libs

   RewriteCond %{REQUEST_URI} !^/tmp

   RewriteCond %{REQUEST_URI} !^/var

   RewriteRule ^/(.*)$ /content/aemsite/en/$1 [PT,L]

this is the log extract:

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (2) init rewrite engine with requested uri /products

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (3) applying pattern '^/$' to uri '/products'

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (3) applying pattern '^/(.*)$' to uri '/products'

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (4) RewriteCond: input='/products' pattern='!^/apps' => matched

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (4) RewriteCond: input='/products' pattern='!^/content' => matched

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (4) RewriteCond: input='/products' pattern='!^/etc' => matched

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (4) RewriteCond: input='/products' pattern='!^/home' => matched

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (4) RewriteCond: input='/products' pattern='!^/libs' => matched

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (4) RewriteCond: input='/products' pattern='!^/tmp' => matched

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (4) RewriteCond: input='/products' pattern='!^/var' => matched

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (2) rewrite '/products' -> '/content/aemsite/en/products'

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (2) forcing '/content/aemsite/en/products' to get passed through to next API URI-to-filename handler

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (2) init rewrite engine with requested uri /products/

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (3) applying pattern '^/$' to uri '/products/'

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (3) applying pattern '^/(.*)$' to uri '/products/'

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (4) RewriteCond: input='/products/' pattern='!^/apps' => matched

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (4) RewriteCond: input='/products/' pattern='!^/content' => matched

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (4) RewriteCond: input='/products/' pattern='!^/etc' => matched

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (4) RewriteCond: input='/products/' pattern='!^/home' => matched

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (4) RewriteCond: input='/products/' pattern='!^/libs' => matched

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (4) RewriteCond: input='/products/' pattern='!^/tmp' => matched

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (4) RewriteCond: input='/products/' pattern='!^/var' => matched

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (2) rewrite '/products/' -> '/content/aemsite/en/products/'

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (2) forcing '/content/aemsite/en/products/' to get passed through to next API URI-to-filename handler

-----------------------------

I am unable to locate why /products is being rewritten to /products/

I think that's the reason behind this whole issue. Please correct me if I am wrong.

Thanks

joerghoh
Adobe Employee
Adobe Employee
March 20, 2018

Hi,

I see this

127.0.0.1 - - [19/Mar/2018:21:23:42 --0400] [aemsite.com/sid#356c590][rid#36080c8/initial] (2) forcing '/content/aemsite/en/products' to get passed through to next API URI-to-filename handler

and this

127.0.0.1 - - [19/Mar/2018:21:23:43 --0400] [aemsite.com/sid#356c590][rid#3592190/initial] (2) init rewrite engine with requested uri /products/

But I don't know if these 2 lines belong to the same request at all... sid# and rid# are identical, but the parameters don't look the same.

Sorry, I am out of ideas atm.

Jörg

Level 4
March 20, 2018

The request to /product gets rewritten to /products/.

I can understand, I am out of ideas too. I tried everything. debugging the virtual hots configuration to dispatcher but nothing seems to resolve this issue.

Thank you for looking into this issue and apologies for it took a lot of your time.

Level 2
August 10, 2018

Hi,

Use DirectorSlash Off to configure mod_dir not to append /.

Regards

Kanika

Adobe Employee
July 4, 2023

I realise this is long after the fact but figured I would add this incase others experience similar issues. I am not sure exactly *where* the forward slash redirect comes from. But to address the issue follow the steps below. 

 

If you have confirmed in the vhost that 

DirectorySlash Off

is configured then also check the dispatcher_vhost.conf  that the following is configured correctly ( read more here )

Options Indexes

 

If you are still experiencing 403 errors on trailing slash then it is most likely caused by the Sling Default GET servlet configuration. This configuration has an "Auto Index" property. If this option is not checked, the request to the resource is forbidden and results in a status 403/FORBIDDEN. You most likely want to leave this unchecked. 

 

Confirm that you have a dispatcher rule in place that grabs paths with trailing slash and appends .html. Pay close attention to your rewrite flags and the order of the rules as these might have an impact on how your rule is processed. Also add RewriteCond's that might be applicable. Example rewrite rule:

RewriteRule ^(.+[^/])(/?)$ $1.html [L,R=301]

  

Lastly you mentioned that you are stripping .html extension using the Link Checker Transformer. Make sure this is really what you want to do in the first place.