Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

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?

5 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

Level 8

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?