Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. LAMP
  3. LMAP .htaccess rewrite rules with google analytics - Help needed

LMAP .htaccess rewrite rules with google analytics - Help needed

Scheduled Pinned Locked Moved Solved LAMP
21 Posts 3 Posters 1.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • nebulonN Offline
    nebulonN Offline
    nebulon
    Staff
    wrote on last edited by
    #3

    I also am not sure how this would be related to .htaccess rewrite ruls. @privsec do you have any more background info on that?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      privsec
      wrote on last edited by
      #4

      When reviewing the code, it states that the index.hmlt is overwritten when using the .htaccess.php

      So I thought it had to be in the .htaccess file. Sigh, so all I have to do is add it to the .html file and it will work?

      1 Reply Last reply
      0
      • robiR Offline
        robiR Offline
        robi
        wrote on last edited by
        #5

        No, for GA you just add the code to the HTML page(s) and that's it. Same for Mautic, Matomo, Ackee, Umami, etc.

        Conscious tech

        1 Reply Last reply
        0
        • P Offline
          P Offline
          privsec
          wrote on last edited by
          #6

          So with GA, I created the data stream and added the TAG as directed after th head tag on the default index.php file that comes with the LAMP app install.

          It isnt detecting traffic, Ill check back on this in 48 hours but even google is saying that it isnt detecting the GA tag.

          1 Reply Last reply
          0
          • robiR Offline
            robiR Offline
            robi
            wrote on last edited by robi
            #7

            If you're actually using .php pages w/o HTML, see https://stackoverflow.com/questions/15201082/where-to-add-google-analytics-code-to-a-php-website

            There is no delay, it should either work or not from the GA console.

            Conscious tech

            1 Reply Last reply
            0
            • P Offline
              P Offline
              privsec
              wrote on last edited by
              #8

              Ok, then something I am doing is wrong. And I don't know what.

              /app/data/public/ .htaccess contains this

              # Permanent URL redirect 
              RewriteEngine on
              Redirect 302 / https://discord.gg/bGH$$$$$$$
              

              /app/data/public/ index.php contains this

              
              <html>
              <head>
                <title> Cloudron LAMP app (PHP 7.4)</title>
              </head>
              
              <!-- Google tag (gtag.js) -->
              <script async src="https://www.googletagmanager.com/gtag/js?id=G-H65R5$%#%@"></script>
              <script>
                window.dataLayer = window.dataLayer || [];
                function gtag(){dataLayer.push(arguments);}
                gtag('js', new Date());
              
                gtag('config', 'G-H65R@#$$%#');
              </script>
              <body>
              </body>
              </html>
              `
              robiR 1 Reply Last reply
              0
              • P privsec

                Ok, then something I am doing is wrong. And I don't know what.

                /app/data/public/ .htaccess contains this

                # Permanent URL redirect 
                RewriteEngine on
                Redirect 302 / https://discord.gg/bGH$$$$$$$
                

                /app/data/public/ index.php contains this

                
                <html>
                <head>
                  <title> Cloudron LAMP app (PHP 7.4)</title>
                </head>
                
                <!-- Google tag (gtag.js) -->
                <script async src="https://www.googletagmanager.com/gtag/js?id=G-H65R5$%#%@"></script>
                <script>
                  window.dataLayer = window.dataLayer || [];
                  function gtag(){dataLayer.push(arguments);}
                  gtag('js', new Date());
                
                  gtag('config', 'G-H65R@#$$%#');
                </script>
                <body>
                </body>
                </html>
                `
                robiR Offline
                robiR Offline
                robi
                wrote on last edited by
                #9

                @privsec If you're trying to use the.php file, why would you intercept it with the 302 redirect?

                Conscious tech

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  privsec
                  wrote on last edited by
                  #10

                  I'm not. I want all traffic going to sub.domain.com to be rerouted to another location.

                  I also want to track how this link is performing.

                  robiR 1 Reply Last reply
                  0
                  • P privsec

                    I'm not. I want all traffic going to sub.domain.com to be rerouted to another location.

                    I also want to track how this link is performing.

                    robiR Offline
                    robiR Offline
                    robi
                    wrote on last edited by
                    #11

                    @privsec You are. Which is why it's not working as you think it should.

                    .htaccess gets evaluated before any file is served.

                    If you want to do what you describe, then do the redirect in your index.php so the GA tag can execute as well.

                    Conscious tech

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      privsec
                      wrote on last edited by
                      #12

                      Ahh, I see. I am using the .php file as that was what was recommended above.

                      If I could do it all in one place than that is preferred.

                      If I do it in the .php file, is the redirect immediate?
                      I do not want the end user to sit and wait or anything

                      1 Reply Last reply
                      0
                      • robiR Offline
                        robiR Offline
                        robi
                        wrote on last edited by
                        #13

                        It's as immediate as you make it, with messages, delays or not.

                        Conscious tech

                        1 Reply Last reply
                        1
                        • P Offline
                          P Offline
                          privsec
                          wrote on last edited by
                          #14

                          Everything I'm finding online keeps referring to use .htaccess to do the redirect.

                          So can you point me in the right direction?

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            privsec
                            wrote on last edited by
                            #15

                            Actually, I just found

                            <!DOCTYPE HTML>
                            <html lang="en-US">
                                <head>
                                    <meta charset="UTF-8">
                                    <meta http-equiv="refresh" content="0; url=http://example.com">
                                    <script type="text/javascript">
                                        window.location.href = "http://example.com"
                                    </script>
                                    <title>Page Redirection</title>
                                </head>
                                <body>
                                    <!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
                                    If you are not redirected automatically, follow this <a href='http://example.com'>link to example</a>.
                                </body>
                            </html>
                            

                            And I found

                            <!DOCTYPE HTML>
                             
                            <meta charset="UTF-8">
                            <meta http-equiv="refresh" content="1; url=http://example.com">
                             
                            <script>
                              window.location.href = "http://example.com"
                            </script>
                             
                            <title>Page Redirection</title>
                             
                            <!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
                            If you are not redirected automatically, follow the <a href='http://example.com'>link to example</a>
                            
                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              privsec
                              wrote on last edited by
                              #16

                              So I still don't know what is wrong. It should be working.

                              image.png

                              This is now what I have in index.php

                              
                              <!DOCTYPE HTML>
                              <html lang="en-US">
                                  <head>
                                      <meta charset="UTF-8"><meta http-equiv="refresh" content="0; url=https://discord.gg/bG$$$$$$$">
                                      <script type="text/javascript">
                                          window.location.href = "https://discord.gg/bGH$$$$$$$"
                                      </script>
                                      <title>Community</title>
                                  </head>
                                  <script async src="https://www.googletagmanager.com/gtag/js?id=G-H65$$$$$$$"></script>
                              <script>
                                window.dataLayer = window.dataLayer || [];
                                function gtag(){dataLayer.push(arguments);}
                                gtag('js', new Date());
                              
                                gtag('config', 'G-H65$$$$$$$');
                              </script>
                                  <body>
                                      <!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
                                      If you are not redirected automatically, follow this <a href='https://discord.gg/bG$$$$$$$'>link to our community</a>.
                                  </body>
                              </html>
                              
                              

                              This is my .htaccess file

                              # Permanent URL redirect 
                              # RewriteEngine on
                              # Redirect 302 / https://discord.gg/b34345345345
                              
                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                privsec
                                wrote on last edited by
                                #17

                                The redirect is working as I would expect it to, but GA isn't working

                                1 Reply Last reply
                                0
                                • robiR Offline
                                  robiR Offline
                                  robi
                                  wrote on last edited by
                                  #18

                                  That does not look like a php file. Perhaps rename it to .html

                                  Conscious tech

                                  1 Reply Last reply
                                  1
                                  • P Offline
                                    P Offline
                                    privsec
                                    wrote on last edited by
                                    #19

                                    Renamed from index.php to index.html

                                    redirect works, GA doesn't

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      privsec
                                      wrote on last edited by
                                      #20

                                      I noticed my GA was outside my head tag (DOH!) but even after moving that, it still isn't being recognized.

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        privsec
                                        wrote on last edited by
                                        #21

                                        AAannnnnd now it is working. I wish I could tell you why, but I don't.

                                        Thanks @robi

                                        1 Reply Last reply
                                        1
                                        • J joseph marked this topic as a question on
                                        • J joseph has marked this topic as solved on
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Bookmarks
                                        • Search