We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10597
    • 31 Posts
    I have been attempting to setup friendly urls for a dynamic page that shows a different chatroom based on a chanid parameter.
    I am using Revolution 2.0.6 or it’s using me I can’t tell which yet.

    The page is setup using the alias ’chatrooms/chatroom’

    My rewriterules:
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule .* - [S=2,L]
    RewriteRule ^chatrooms/([^/]+)/([^/]+)/?$ index.php?q=chatrooms/$1/?chanid=$2 [L]
    RewriteRule ^(.*)$ index.php?q=$1 [L]


    This URL (/chatrooms/chatroom/12345/)will do a rewrite correctly to:
    index.php?q=chatrooms/chatroom/?chanid=12345 but shows a 404 page. It appears if it is trying to check the alias ’chatrooms/chatroom/?chanid=12345’ instead of ’chatrooms/chatroom/’ and adding the parameter ’chanid=12345’


    If I change
    RewriteRule ^chatrooms/([^/]+)/([^/]+)/?$ index.php?q=chatrooms/$1/?chanid=$2 [L]

    To read
    RewriteRule ^chatrooms/([^/]+)/([^/]+)/?$ index.php?q=chatrooms/$1/ [L]

    everythng works as expected but of course I don’t get the chanid to display the correct room.

    If I change to this:
    RewriteRule ^chatrooms/([^/]+)/([^/]+)/?$ index.php?q=chatrooms/$1/&chanid=$2 [L]

    Then index.php does a redirect to /chatrooms/chatroom/ and loses the chanid.

    So how is it I can pass the chanid to index.php and stop it from doing a redirect and removing the chanid parameter.

    I would appreciate any help here. I have been working on this one line of htaccess code for 2 days now. As far as I can tell this code is working correctly but then MODx does something I am not expecting or don’t understand why it is doing it.

    Thanks
      Using ModX Revolution
      • 10597
      • 31 Posts
      Ok, I have managed to fix this issue.
      What I wanted was to create a dynamic URL with friendly URLs running. This resource would take a parameter from either the URL or from a query string and create a page based on that input. This is something that is easily done with php and htaccess normally.

      The problem I ran into is modx would trash the extra parameter when using the alias. (index.php?q=alias&extraparam=1) would be redirected to (index.php?q=alias).

      What I had to do was create the URL so that it was using a non-existent alias and rewrite that in htaccess to the correct alias with the extra parameters. You could then use a $_GET call or access the parameter in the $modx array ($modx->request->parameters[’GET’][’extraparam’])

      htaccess code

      RewriteCond %{REQUEST_FILENAME} -f [OR]
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule .* - [S=2,L]
      #old line Friendly URL using real alias
      #RewriteRule ^chatrooms/([^/]+)/([^/]+)/?$ index.php?q=chatrooms/$1/&chanid=$2 [L]
      #Friendly URL -- fake alias rewrote to real alias with params
      RewriteRule ^chat/([^/]+)/([^/]+)/?$ index.php?q=chatrooms/$1/&chanid=$2 [L]
      RewriteRule ^(.*)$ index.php?q=$1 [L]


      I know this is a dirty workaround. There is probably a better/cleaner way to do this. In my opinion, the first way to the real alias should have worked. You should be able to send parameters to any page on the site without having to go through this and still be able to access them in the REQUEST/SERVER/GET/POST arrays. Maybe someone else can look into the reasoning for this behavior.

      I hope this helps someone else also.
        Using ModX Revolution
        • 10597
        • 31 Posts
        I am doing a full fresh reinstall with the latest version of Revo today. Just to see where in the process of setting up this site it breaks.

        If anyone has any ideas on what to check for in the process I would love to hear it.
          Using ModX Revolution
          • 10597
          • 31 Posts
          For me his issue was created when you set the html extension to "/".
          I haven’t tested it if also happens when you set it to nothing.

          I am not positive that some of the FURL settings didn’t also help create this problem.

          I set the extension back to .html.
          Changed "Use Friendly Alias Path" to Yes

          And the custom parameters were placed in the query string again.
          Before that they were dropped even though they still appeared in REQUEST_URI.
            Using ModX Revolution
            • 3749
            • 24,544 Posts
            I’m not sure if this is relevant to your issue, but you can put parameters for $_GET in a link with FURLs on like this:

            <a href = "[[~12? &paramName=`value`]]"> Link Text</a>
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting