Expand my Community achievements bar.

How to access pages without adding .HTML extention to the urls

Avatar

Level 4

Hi ,
I want AEM URLs without html extension how can i achieve this?

6 Replies

Avatar

Level 4

Below is my rewrite.rules file i have added 
RewriteCond %{REQUEST_URI} !\.(html|jpg|jpeg|gif|png|tif|pdf|doc|docx|xls|xlsx|ppt|pptx|swf|css|js|svg)$
But when i am accessing http://localhost:4502/editor.html/content/us/en/test/
i am getting 403 FORBIDDEN Error and even i remove the rule i can't access the url without ext



..................................

rewrite.rules

#
# This file contains the rewrite rules, and can be customized.
#
# By default, it includes just the rewrite rules. You can
# add rewrite rules to this file but you should still include
# the default rewrite rules.

Include conf.d/rewrites/default_rewrite.rules

RewriteCond %{REQUEST_URI} !\.(html|jpg|jpeg|gif|png|tif|pdf|doc|docx|xls|xlsx|ppt|pptx|swf|css|js|svg)$


RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/system
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteCond %{REQUEST_URI} (.html|.jpe?g|.png|.svg)$

# rewrite for root redirect
RewriteRule ^/?$ /content/cisco-dcloud/us/en/home.html [PT,L]

RewriteRule ^/en/(.*)$ /content/cisco-dcloud/us/en/$1 [PT,L]

RewriteRule ^/us/en/(.*)$ /content/cisco-dcloud/us/en/$1 [PT,L]

RewriteRule ^/services/(.*)$ /content/cisco-dcloud/us/en/home/services/$1 [PT,L]

# Rewrite rules for custom error pages
ErrorDocument 404 /services/404.html

# RewriteCond %{REQUEST_URI} ^/us/.*
# RewriteCond %{HTTP:x-aem-variant} ^.*$
# RewriteRule ^([^?]+)\.(html.*)$ /content/cisco-dcloud$1.%{HTTP:x-aem-variant}.$2 [PT,L]

 

Avatar

Community Advisor

Hi @tatrived 

To access pages without adding the `.html` extension to the URLs in AEM, you can configure the Apache Sling Resource Resolution to remove the extension. Here's how you can do it:

1. Open the AEM Web Console by navigating to `http://localhost:4502/system/console/configMgr` (replace `localhost:4502` with your AEM instance URL if necessary).

2. Search for the "Apache Sling Resource Resolver Factory" configuration and click on it to open the configuration page.

3. In the configuration page, locate the "Resource Resolver Mapping" section.

4. Add a new entry to the "URL Mappings" field. The entry should have the following format: `/content=/content.html`. This mapping tells AEM to resolve URLs without the `.html` extension.

5. Save the configuration.

After making this configuration change, you should be able to access pages without adding the `.html` extension to the URLs. For example, if you have a page with the path `/content/mysite/mypage`, you can access it using the URL `http://localhost:4502/content/mysite/mypage` instead of `http://localhost:4502/content/mysite/mypage.html`.

Please note that modifying the resource resolution configuration can have implications on the overall URL structure and may require adjustments to your website's links and references. It's recommended to thoroughly test the changes and ensure they align with your specific requirements and use cases. 

RajaReddy_3370_0-1706886027398.png

 

Configure Dispatcher:

If you are using AEM Dispatcher as a caching and load balancing component, you need to configure it to handle URLs without the ".html" extension.

  1. Open the Dispatcher configuration file:

    • Locate the dispatcher.any file (typically found in /etc/httpd/conf.d/ or /etc/apache2/conf.d/).
    • Edit the file with a text editor.
  2. Add a URL rewrite rule:

    • Add a rule to rewrite URLs without ".html" to include ".html". For
      /url "/content/(.*[^/])$" "/content/$1.html"
      This rule ensures that if the URL doesn't end with a "/", it is rewritten to include ".html".
  3. Save the configuration.

3. Update Links in AEM Components:

After making these changes, ensure that links in your AEM components do not include the ".html" extension. AEM will automatically resolve URLs based on the configuration changes.

4. Clear Dispatcher Cache:

If you are using the AEM Dispatcher, clear the cache to ensure that the new configuration takes effect.



Avatar

Level 4

Add a new entry to the "URL Mappings" field. in Sling Resource Resolver Factory giving error in all URL "

HTTP ERROR 404 Not Found
URI:/STATUS:404MESSAGE:Not FoundSERVLET:org.apache.felix.http.base.internal.dispatch.DispatcherServlet-635f19f2


and for 
Configure Dispatcher 
in my dispatcher.any this is already written
#
# This is a file provided by the runtime environment and only included for
# illustration purposes.
#
# DO NOT EDIT this file, your changes will have no impact on your deployment.
#
 
/farms {
# Include all *.farm files in enabled_farms
$include "enabled_farms/*.farm"
}


I am new to AEM can someone guide me step by step?

Avatar

Community Advisor

Step-1 : Please enable Debug logs on dispatcher to understand how URLs are being rewritten. Baseline variables are predefined in the file conf.d/variables/global.vars. These default variables, like DISP_LOG_LEVEL, REWRITE_LOG_LEVEL, etc., ensure non-null values. Edit conf.d/variables/global.vars to modify values

Define DISP_LOG_LEVEL info
Define REWRITE_LOG_LEVEL trace2

The rewrite logs for AEMaaCS SDK are written in /etc/httpd/logs/httpd_error.log

Sample logs:

[Thu Aug 31 10:46:08.251355 2023] [rewrite:trace2] [pid 360:tid 140516768209720] mod_rewrite.c(493): [client 172.17.0.1:41744] 172.17.0.1 - - [localhost/sid#7fcc9c28a588][rid#7fcc9bb75fc0/initial] init rewrite engine with requested uri /en.html
[Thu Aug 31 10:46:08.251441 2023] [rewrite:trace2] [pid 360:tid 140516768209720] mod_rewrite.c(493): [client 172.17.0.1:41744] 172.17.0.1 - - [localhost/sid#7fcc9c28a588][rid#7fcc9bb75fc0/initial] rewrite '/en.html' -> '/content/wknd/us/en.html'
[Thu Aug 31 10:46:08.251453 2023] [rewrite:trace2] [pid 360:tid 140516768209720] mod_rewrite.c(493): [client 172.17.0.1:41744] 172.17.0.1 - - [localhost/sid#7fcc9c28a588][rid#7fcc9bb75fc0/initial] forcing '/content/wknd/us/en.html' to get passed through to next API URI-to-filename handler

Source: https://techrevel.blog/2023/09/01/aem-dispatcher-filters-ignoreurlparams-virtualhosts-rewrites/

 

Step-2: Update the rewrite rule in the file specific to your app. The file would be present in conf.d/rewrites

 

Step-3: Check with your team, if they are using Sling Mapping for URL shortening etc. If yes, please follow the section " Enable etc/map configuration in AEM(Publisher)" on https://www.albinsblog.com/2018/04/how-to-implement-extension-less-urls-in-adobe-experience-manager.... 

Else, define the rewrite rules as defined in "Apache configurations" on above link.


Aanchal Sikka