open graph tags not working angular 7 project











up vote
0
down vote

favorite












I added the og tags required to show the rich content while pasting the URL anywhere on social media. It only works when the route is:



https://example.com



but does not work when other components route is attached to it:



https://example/register



it gives 404 error with this URL whereas it opens this URL on the browser perfectly.



Also,



Curl https://example.com/ (Works)



Curl https://example.com/path (404)



Head section from both the URL(s) are same and are visible when viewing the page source. But somehow, the facebook debugger or any other social media crawler, for that matter, ignore the head tag from /register route but picks the information from /



I have been searching for solutions on this forum and many others. I concluded that people are saying something about Angular Universal but somehow I am not convinced that that mine is the case similar to those. If so, which solution to implement.










share|improve this question
























  • you should give us a real example, not just "example.com", that would make answers a lot easier and faster. always include stuff to test.
    – luschn
    Nov 18 at 21:14















up vote
0
down vote

favorite












I added the og tags required to show the rich content while pasting the URL anywhere on social media. It only works when the route is:



https://example.com



but does not work when other components route is attached to it:



https://example/register



it gives 404 error with this URL whereas it opens this URL on the browser perfectly.



Also,



Curl https://example.com/ (Works)



Curl https://example.com/path (404)



Head section from both the URL(s) are same and are visible when viewing the page source. But somehow, the facebook debugger or any other social media crawler, for that matter, ignore the head tag from /register route but picks the information from /



I have been searching for solutions on this forum and many others. I concluded that people are saying something about Angular Universal but somehow I am not convinced that that mine is the case similar to those. If so, which solution to implement.










share|improve this question
























  • you should give us a real example, not just "example.com", that would make answers a lot easier and faster. always include stuff to test.
    – luschn
    Nov 18 at 21:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I added the og tags required to show the rich content while pasting the URL anywhere on social media. It only works when the route is:



https://example.com



but does not work when other components route is attached to it:



https://example/register



it gives 404 error with this URL whereas it opens this URL on the browser perfectly.



Also,



Curl https://example.com/ (Works)



Curl https://example.com/path (404)



Head section from both the URL(s) are same and are visible when viewing the page source. But somehow, the facebook debugger or any other social media crawler, for that matter, ignore the head tag from /register route but picks the information from /



I have been searching for solutions on this forum and many others. I concluded that people are saying something about Angular Universal but somehow I am not convinced that that mine is the case similar to those. If so, which solution to implement.










share|improve this question















I added the og tags required to show the rich content while pasting the URL anywhere on social media. It only works when the route is:



https://example.com



but does not work when other components route is attached to it:



https://example/register



it gives 404 error with this URL whereas it opens this URL on the browser perfectly.



Also,



Curl https://example.com/ (Works)



Curl https://example.com/path (404)



Head section from both the URL(s) are same and are visible when viewing the page source. But somehow, the facebook debugger or any other social media crawler, for that matter, ignore the head tag from /register route but picks the information from /



I have been searching for solutions on this forum and many others. I concluded that people are saying something about Angular Universal but somehow I am not convinced that that mine is the case similar to those. If so, which solution to implement.







angular facebook-opengraph meta-tags angular7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 16:23

























asked Nov 18 at 19:28









Junaid Qureshi

62




62












  • you should give us a real example, not just "example.com", that would make answers a lot easier and faster. always include stuff to test.
    – luschn
    Nov 18 at 21:14


















  • you should give us a real example, not just "example.com", that would make answers a lot easier and faster. always include stuff to test.
    – luschn
    Nov 18 at 21:14
















you should give us a real example, not just "example.com", that would make answers a lot easier and faster. always include stuff to test.
– luschn
Nov 18 at 21:14




you should give us a real example, not just "example.com", that would make answers a lot easier and faster. always include stuff to test.
– luschn
Nov 18 at 21:14












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Thanks to filipesilva from https://github.com/angular/angular-cli/issues/5113 for pointing out the solution at: https://angular.io/guide/deployment



Problem was with the .htaccess redirection. I knew that index.html fallback was necessary so I implemented the below solution:



RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_FILENAME} index.html
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


But it wasn't very helpful for some reason. Browser was not giving error but curl was. So I have changed the .htaccess file content to:



RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html


right from https://angular.io/guide/deployment & works like a charm.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364656%2fopen-graph-tags-not-working-angular-7-project%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Thanks to filipesilva from https://github.com/angular/angular-cli/issues/5113 for pointing out the solution at: https://angular.io/guide/deployment



    Problem was with the .htaccess redirection. I knew that index.html fallback was necessary so I implemented the below solution:



    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{REQUEST_FILENAME} index.html
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


    But it wasn't very helpful for some reason. Browser was not giving error but curl was. So I have changed the .htaccess file content to:



    RewriteEngine On
    # If an existing asset or directory is requested go to it as it is
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    RewriteRule ^ - [L]
    # If the requested resource doesn't exist, use index.html
    RewriteRule ^ /index.html


    right from https://angular.io/guide/deployment & works like a charm.






    share|improve this answer

























      up vote
      0
      down vote













      Thanks to filipesilva from https://github.com/angular/angular-cli/issues/5113 for pointing out the solution at: https://angular.io/guide/deployment



      Problem was with the .htaccess redirection. I knew that index.html fallback was necessary so I implemented the below solution:



      RewriteEngine On
      RewriteCond %{HTTPS} !=on
      RewriteCond %{REQUEST_FILENAME} index.html
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


      But it wasn't very helpful for some reason. Browser was not giving error but curl was. So I have changed the .htaccess file content to:



      RewriteEngine On
      # If an existing asset or directory is requested go to it as it is
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
      RewriteRule ^ - [L]
      # If the requested resource doesn't exist, use index.html
      RewriteRule ^ /index.html


      right from https://angular.io/guide/deployment & works like a charm.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Thanks to filipesilva from https://github.com/angular/angular-cli/issues/5113 for pointing out the solution at: https://angular.io/guide/deployment



        Problem was with the .htaccess redirection. I knew that index.html fallback was necessary so I implemented the below solution:



        RewriteEngine On
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_FILENAME} index.html
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


        But it wasn't very helpful for some reason. Browser was not giving error but curl was. So I have changed the .htaccess file content to:



        RewriteEngine On
        # If an existing asset or directory is requested go to it as it is
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
        RewriteRule ^ - [L]
        # If the requested resource doesn't exist, use index.html
        RewriteRule ^ /index.html


        right from https://angular.io/guide/deployment & works like a charm.






        share|improve this answer












        Thanks to filipesilva from https://github.com/angular/angular-cli/issues/5113 for pointing out the solution at: https://angular.io/guide/deployment



        Problem was with the .htaccess redirection. I knew that index.html fallback was necessary so I implemented the below solution:



        RewriteEngine On
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_FILENAME} index.html
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


        But it wasn't very helpful for some reason. Browser was not giving error but curl was. So I have changed the .htaccess file content to:



        RewriteEngine On
        # If an existing asset or directory is requested go to it as it is
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
        RewriteRule ^ - [L]
        # If the requested resource doesn't exist, use index.html
        RewriteRule ^ /index.html


        right from https://angular.io/guide/deployment & works like a charm.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 12:55









        Junaid Qureshi

        62




        62






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364656%2fopen-graph-tags-not-working-angular-7-project%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy