Hi ,
How to add .html to extensionless URL in rewrite rules.
When I tried the below code it is appending the .html but unfortunately the domain or language page is also getting affected by the same.
# Add .html for extensionless url's
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^/(.*)$ /$1.html [R=301,L]
For example : In the below example .html shouldn't get added to the 1 & 2 but it should append to 3 & 4
2. https://www.example.com/en_US
3. https://www.example.com/en_US/test
4. https://www.example.com/en_US/test/testingPage
Solved! Go to Solution.
Views
Replies
Total Likes
This condition
RewriteCond %{REQUEST_URI} !^/$
in the rule should already handle that. Do you have any other rewrite rules that may be re-processing?
Hi @nivethaS
Please check https://medium.com/tech-learnings/how-to-implement-extension-less-urls-in-aem-a3136c71b232
Hi @arunpatidar
I already gone through the same but here my condition is when user hits the page without .html it should append .html. In that case
#Replace the .html with /
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^/(.*).html$ /$1/ [R=301,L,QSA]
Will this line work? Because we will have URL like
Try this,
# Rewrite to add html extension if a url does not end with a known extension
RewriteCond %{REQUEST_URI} !^/[a-zA-Z0-9_-]+$ [NC]
RewriteCond %{REQUEST_URI} !\.(html|pdf|xml|json|txt|ico|php|png|jpg|gif|aspx|css|js)$
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ $1.html
You don't need do the 301 or any other redirect in case of appending .html.
Thanks this works but it is adding .html to the https://www.example.com
Is it possible to ignore this, please advice
This condition
RewriteCond %{REQUEST_URI} !^/$
in the rule should already handle that. Do you have any other rewrite rules that may be re-processing?
Views
Likes
Replies