Remove trailing slash from url using rewrite rule | Community
Skip to main content
supriya-hande
Level 4
Jul 9, 2023 3:05 PM UTC
Solved

Remove trailing slash from url using rewrite rule

Hello Team,

 

I am getting 403 forbidden error when accessing page with trailing slash at the end like: https://host/products/productname/
If I access page without slash at the end of the url it works fine like https://host/products/productname
To resolve this issue I tried adding rewrite rule inside Ifmodule as below:
# To remove a trailing slash from the end of the URL
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.*)/$ /$1 [L,R=301]
</IfModule>

But still am getting same error 403 forbidden. Anything going wrong here? Please let me know if anyone has experienced such issue.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Mahedi_Sabuj
Mahedi_SabujAccepted solution
New Participant
Jul 10, 2023 7:34 AM UTC

Hello @supriya-hande, you can try this:

 

 

<IfModule disp_apache2.c> DirectorySlash Off SetHandler dispatcher-handler </IfModule>

 

 

Reference: https://helpx.adobe.com/id_id/experience-manager/kb/403-forbidden-response-images-using-Dispatcher.html

Mahedi Sabuj

4 replies

Mahedi_Sabuj
Mahedi_SabujAccepted solution
New Participant
Jul 10, 2023 7:34 AM UTC

Hello @supriya-hande, you can try this:

 

 

<IfModule disp_apache2.c> DirectorySlash Off SetHandler dispatcher-handler </IfModule>

 

 

Reference: https://helpx.adobe.com/id_id/experience-manager/kb/403-forbidden-response-images-using-Dispatcher.html

Translate
Mahedi Sabuj
supriya-hande
Level 4
Jul 10, 2023 11:19 AM UTC

Hi @mahedi_sabuj thanks for your reply. But DirectorySlash Off is already there in our projects .vhost file inside /my-aem-project/dispatcher/src/conf.d/available_vhosts/aemproject.vhost

Not sure if we need to add explicit rewrite rule for it.

Translate
Mahedi_Sabuj
New Participant
Jul 10, 2023 1:34 PM UTC

Hi @supriya-hande, Can you please share the disp_apache2.c section from the vhost? 

Translate
Mahedi Sabuj
aanchal-sikka
New Participant
Jul 9, 2023 5:14 PM UTC

Hello @supriya-hande 

 

The following rule should work.

RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+?)/$ $1 [R=301,L]

 

 

Translate
Aanchal Sikka