Hi AEM Community,
I have a domain name "xyz" which I want to redirect to my homepage in AEM.
I have done the below -
1. Defined VHost File as below -
<IfModule mod_rewrite.c>
RewriteEngine On
Include conf.d/rewrites/rewrite.rules
# Add .html extension when extension is missing from request
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]*[^./])$ $1.html [R=301,L]
<LocationMatch "^\/content\/dam.*\.(pdf|jpe?g|png|gif|txt|xml).*">
Header unset "Content-Disposition"
Header set Content-Disposition inline
</LocationMatch>
# custom rewrites
#Redirect Root page request to home page
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /content/xyz/us/en/home-page.html [PT,L]
# rewrite for root redirect - Alternative
# RewriteRule ^/?$ /content/xyz/us/en/home-page.html [R=302,L]
</IfModule>
I wrote the above rule in my vhost file but get the below error log in dispatcher
172.17.0.1 "xyz:8080" - [27/Jul/2022:11:40:29 +0000] "GET / HTTP/1.1" 404 5615 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0"
[27/Jul/2022:11:40:29 +0000] "GET /content/xyz/us/en/errors/404.html HTTP/1.1" - hit [publishfarm/-] 15ms "xyz:8080"
I have defined an Error Document directive too as below -
ErrorDocument 404 /content/xyz/us/en/errors/404.html
Can you help as to why the redirect is not working ?
The root is getting mapped directly to the ErrorDocument Directive.
Likes
Total Posts
Correct reply
Jörg_Hoh Any quick help on this ?
Solved! Go to Solution.
Hi All,
Putting the rewrite rules in rewrite.rule file worked for me as against putting them in vhost file directly.
I am still facing the issue of not able to include multiple rewrite files in my rewrite folder even though the opt-in folder with USE_SOURCES_DIRECTLY file being present in my dispatcher configuration.
Another observation that even though the docker image comments the apache rewrite module by default.
If we run the validator's allowlist command we can see the apache rewrite module is enabled.
The directives allowed in Apache configuration files can be listed by running the validator’s allowlist command:
C:\Users\rohan.garg\aem-sdk\dispatcher\aem-sdk-dispatcher-tools-2.0.91-windows\bin>validator allowlist
Cloud manager validator 2.0.34
Allowlisted directives:
RewriteCond
RewriteEngine
RewriteMap
RewriteOptions
RewriteRule
Hope this helps!
Thanks,
Rohan Garg
I feel its because of the rule of adding .html extn
What may be happening is:
1. Request for root domain reach to apache as URI "/"
2. the add .html extn update URI to "/.html"
Now this URI does not map to any further rule, so throw 404.
Try moving this rule towards the end
# Add .html extension when extension is missing from request RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]*[^./])$ $1.html [R=301,L]
Hi @Mohit_KBansal, Thanks for the quick reply.
Moving the .html extension also did not work.
If we look at the logs in dispatcher -
172.17.0.1 "xyz:8080" - [27/Jul/2022:12:13:21 +0000] "GET /?cache HTTP/1.1" 404 5615 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0"
[27/Jul/2022:12:13:21 +0000] "GET /content/xyz/us/en/errors/404.html HTTP/1.1" - miss [publishfarm/0] 168ms "xyz:8080"
The request is logged as "GET /?cache" so the / getting converted to /.html might not be the issue anyways.
Check your apache rewrite logs and try to debug which rule is converting request to /?cache
/?cache comes because I hit the request as xyz:8080/?cache - so the query parameter is getting appended which is fine.
I think the issue might be due to not enabling mod_rewrite in the docker's apache image.
Any idea how that is done ?
Hi All,
A quick update on the problem -
In docker I navigated to the path - /etc/apache2 and opened the httpd.conf in vim editor # vi httpd.conf
I manually uncommented the part #LoadModule rewrite_module modules/mod_rewrite.so
I am saving the file using :w
But every time I restart the server the changes are overridden and the rewrite module is commented again.
Can you please help with this ?
The problem seems to be in the inclusion of rewrite module of apache.
Hi All,
Putting the rewrite rules in rewrite.rule file worked for me as against putting them in vhost file directly.
I am still facing the issue of not able to include multiple rewrite files in my rewrite folder even though the opt-in folder with USE_SOURCES_DIRECTLY file being present in my dispatcher configuration.
Another observation that even though the docker image comments the apache rewrite module by default.
If we run the validator's allowlist command we can see the apache rewrite module is enabled.
The directives allowed in Apache configuration files can be listed by running the validator’s allowlist command:
C:\Users\rohan.garg\aem-sdk\dispatcher\aem-sdk-dispatcher-tools-2.0.91-windows\bin>validator allowlist
Cloud manager validator 2.0.34
Allowlisted directives:
RewriteCond
RewriteEngine
RewriteMap
RewriteOptions
RewriteRule
Hope this helps!
Thanks,
Rohan Garg