Expand my Community achievements bar.

Redirection for a particular page

Avatar

Level 2

Hi Team,

In one of our application for a angular video component is developed. This is a training page where multiple videos are being maintained in the DAM. the urls links are being generated using the angular route. If a page is bookmarked or being directly hit, it results in 404. Instead it should take me to /home.html. Could you please help me with the providing a redirect all the video urls to the specific url.

4 Replies

Avatar

Community Advisor

Hi @AnushaAt 

If you want to redirect all your video urls to a particular path you can add the rule in apache rewrite. If the url contains videos it will redirect to home in the below case

 

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/videos/.*$ [NC]
RewriteRule ^/videos/.*$ /home.html [R=302,L]

Avatar

Community Advisor

Hi @AnushaAt 

Please check sample dispatcher rule.

 

# Redirect all video URLs to /home.html if accessed directly
RewriteCond %{REQUEST_URI} ^/path-to-videos/.*$ [NC]
RewriteRule ^.*$ /home.html [L,R=302]

 



Arun Patidar

Avatar

Community Advisor

Hi @AnushaAt ,

When users bookmark or directly hit a video page URL, and it causes a 404, you want to redirect all such requests to /home.html.

This requires:

     - Apache Rewrite Rule in your Dispatcher configuration.

     - Optionally, Angular route fallback (if routing is part of the issue).

Dispatcher (Apache) Rewrite Rule

1. Enable Rewrite Engine (if not already enabled)

RewriteEngine On

2. Add Rewrite Rule in dispatcher /conf.d/ (e.g., vhost or separate file)

Sample Rewrite Rule — Redirect all /videos/... URLs to /home.html

# Redirect all URLs under /videos/ to /home.html
RewriteCond %{REQUEST_URI} ^/videos/.*$ [NC]
RewriteRule ^/videos/.*$ /home.html [R=302,L]

3. For DAM URLs (e.g., /content/dam/training-videos/...), use this rule

# Redirect DAM video URLs to /home.html
RewriteCond %{REQUEST_URI} ^/content/dam/training-videos/.*$ [NC]
RewriteRule ^/content/dam/training-videos/.*$ /home.html [R=302,L]

4. If Angular is routing via hash-based URLs or SPA routing, and direct URL hits cause 404, redirect any unknown routes to /home.html:

# Redirect any unknown route (not a real AEM page) to /home.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/videos/.*$ /home.html [R=302,L]

To verify:
     - Access /videos/any-video directly – should redirect to /home.html.

     - Access /content/dam/training-videos/video.mp4 – should redirect.

     - Use 302 for temporary testing; switch to 301 for permanent redirects after confirmation.


Angular Fallback (Only if Needed)

If Angular routes are causing 404s due to SPA routing:

Add this to angular.json → "baseHref": "/".

In index.html:

<base href="/">

Add catch-all route in Angular:

{ path: '**', redirectTo: '/home' }

 

Dispatcher Rule Example

RewriteEngine On

# Redirect all /videos/ URLs to /home.html
RewriteCond %{REQUEST_URI} ^/videos/.*$ [NC]
RewriteRule ^.*$ /home.html [R=302,L]

# Redirect all DAM video paths to /home.html
RewriteCond %{REQUEST_URI} ^/content/dam/training-videos/.*$ [NC]
RewriteRule ^.*$ /home.html [R=302,L]

 

Regards,
Amit

 

Avatar

Level 2

Hi Amit,

 

Thanks for your response,

 

I have tried the below rewrite rule, since the page exist in Angular

# Redirect any unknown route (not a real AEM page) to /home
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/videos/.*$ /home [R=302,L]

 

The page is getting redirected to AEM page but the Angular page which contains videos throws 404.  We are not able to see the videos. but the redirect works. 

 

May I know Is there any other rules I can try it . It will be helpful, If I get some suggestion on this. 

 

Regards,

Anusha