We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19975
    • 429 Posts
    I am looking to host MODX alongside a booking system, both systems will use the same "www.domain.com/url-zone" area meaning that both will need to co-exist.

    At current I have located the following files/directories as such;

    public_html/
    public_html/bookingsystem/
    public_html/assets/
    public_html/connectors/
    public_html/core/
    public_html/manager/
    public_html/.htaccess
    public_html/config.core.php
    public_html/index.php
    public_html/bookings.php


    The booking system uses a .php extension and as such I have inserted the following code in my .htaccess file;

    RewriteEngine On
    RewriteRule ^(.*)-(\d+).html$ ?controller=pjListings&action=pjActionView&id=$2
    RewriteBase /beta/
    
    RewriteCond %{THE_REQUEST} (.*)\.php  
    RewriteRule ^(.*)\.php $1.html [R=301,NE]  
    
    RewriteCond %{THE_REQUEST} (.*)\.html  
    RewriteRule ^(.*)\.html $1.php [NE]  


    Unfortunately as the above code seems to change all .php to .html system file paths within the MODX manager nolonger functions correctly. I am not completely au fait with htaccess commands so if anyone can provide advise I'd be grateful.


    [ed. note: SandersDesign last edited this post 11 years, 11 months ago.]
      Martin Sanders - Design & Web Development
      • 38850
      • 110 Posts
      It looks like the only parts to the booking system are the /bookingsystem/ folder and the booking.php file, is this correct?

      Because the single index.php file will be the entry point to MODX I assume, then the entry point to the booking system is going to be what? Do you type "/example.com/bookingsystem" to get to it? Or do you go directly to the booking.php file like "/example.com/booking.php"?

      The entry point for each system is important. MODX can be configured to exist in an entirely different folder outside the web root, so it has the ability to move things around.

      If the entry point to your booking system is through the folder itself, then you would have another htaccess file IN that folder to control things from there. The htaccess file in the root folder would then be used almost exclusively for MODX.

      If the entry point is to access booking.php directly, then you might have to add an exclusion for it in MODX's normal default htaccess file.

      Please post what the entry points are. I also see you have a base of "/beta/" and yet all your files are in the public_html folder (not in a /base/ folder). This could be the issue too unless it was just a mistaken copy/paste from two different servers?
        • 19975
        • 429 Posts
        The bookingsystem generates pages for each property, example www.example.com/property-name-idNum.html. There are likely to be several hundred property pages. To access the bookingsystem manager users will access www.example.com/bookingsystem.html?admin=adminURL .

        I have solved the MODX manager URL issue by adding a "RewriteEngine Off" to each of the MODX directories however I am now unable to access any of the www.example.com/property-name-idNum.html pages as these URLs now default to the MODX index.

        All files are currently in the /beta directory, this was a slight miss communication, sorry wink.
          Martin Sanders - Design & Web Development
          • 19975
          • 429 Posts
          I've updated the htaccess to

          RewriteEngine On
          RewriteRule ^(.*)-(\d+).html$ bookingsystem.html?controller=pjListings&action=pjActionView&id=$2
          RewriteBase /beta/
          
          RewriteCond %{THE_REQUEST} (.*)\.php  
          RewriteRule ^(.*)\.php $1.html [R=301,NE]  
          RewriteCond %{THE_REQUEST} (.*)\.html  
          RewriteRule ^(.*)\.html $1.php [NE]  
          
          # The Friendly URLs part
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


          This now shows the property pages but not MODX page.html URLS.
            Martin Sanders - Design & Web Development
            • 38850
            • 110 Posts
            A few notes for you.

            You have the RewriteBase directive UNDER the first RewriteRule, is this correct or should it be above so that it is rewritten properly? This is likely not the problem though.

            In your first rewriterule, you point it to "bookingsystem.html". Isn't it supposed to be a php extension from your earlier file listing?

            The entire middle section doesn't make sense to me. I'm trying to think about this logically since I can't really duplicate your entire situation. It seems like your saying, if anything is a ".php" then send it to the ".html" version. But immediately after you tell it if anything is a ".html" then send it to the ".php" version. What is the point of that?

            Rewrite rules are tricky things. Typically once you've rewritten the URL and the system redirects, it will immediately run through the rules again with the new URL, this can lead to infinite loops, keep this in mind. If you are rewriting a URL, what would happen if the NEW URL went through your rules again?

            I'm not sure you need the middle section, as the MODX default FURL entries will take care of all the MODX URLs. Unless there is some other special purpose?

            The only real change you are trying to make is "detect" certain booking URLs and rewrite those to a different handler which is bookingsystem.php. You need to make sure no other rules are followed after this one, because no other MODX rules would be necessary if the bookingsystem is used, yes?
            So after you rewrite a booking URL, you may need the "(END)" flag to tell it to not process any more rules for this round of requests.

            You may also need to tell the system that if it's already using the bookingsystem.php file, then skip rewrites. Something like this at the top:
            RewriteCond %{REQUEST_URI} !=/bookingsystem.php

            Because remember, in you regex you are looking for "any characters, and then a dash". So if the URL already is going to "bookingsystem.php", it would still rewrite it.

            I hope a few of these notes help you solve it. Maybe you can explain those middle rules you have, is it something special you're doing in MODX?
            Also, if it helps you separate the two functions of your site, you can tell MODX to NOT use the ".html" extension for its pages, then you wouldn't have to worry about looking for it.

            And when you say the MODX html pages aren't working, what exactly is happening? Are they being rewritten? To what? Server error?
              • 19975
              • 429 Posts
              Hi vigilante,

              Thanks for you detailed post, I have learnt alot from your kind comments wink

              The updated .htaccess file now removes the .html/.php suffixes and returns the correct pages for entered URLs.

              Within MODX I have updated the html MODX Content Type resource to suffix .php which is then removed via my RewriteRule ^(.*)\.php $1 [R=301,L,NE] command.

              I have also shorted the login/password/register URLs however I have been unable to redirect these system pages to the shortened URLs. This is of course desirable as it removes potential duplicate content issues.

              RewriteEngine On
              RewriteBase /beta/
              
              RewriteRule ^(.*)-(\d+)$ bookingsystem.php?controller=pjListings&action=pjActionView&id=$2 [L]
              RewriteRule ^login$ bookingsystem.php?controller=pjListings&action=pjActionLogin [L]
              RewriteRule ^forgotpassword$ bookingsystem.php?controller=pjListings&action=pjActionForgotPassword [L]
              RewriteRule ^register$ bookingsystem.php?controller=pjListings&action=pjActionRegister [L]
              RewriteRule ^([^\.]+)$ $1.php [L]
              
              RewriteCond %{THE_REQUEST} (.*)\.php  
              RewriteRule ^(.*)\.php $1 [R=301,L,NE]  
              
              RewriteCond %{THE_REQUEST} (.*)\.html  
              RewriteRule ^(.*)\.html $1 [R=301,L,NE]  
              
              # MODX The Friendly URLs part
              RewriteCond %{REQUEST_URI} !=/bookingsystem.php
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule ^(.*)$ index.php?q=$1 [QSA]
                Martin Sanders - Design & Web Development
                • 38850
                • 110 Posts
                Sorry I didn't get back in a couple days. Thanks for the kind words!

                In the middle, when you strip out the php and html extensions and send a 301 redirect, the htaccess file will be ran through again on the new URL. So like /example.html will redirect to "example" and once again be processed by htaccess. So in the MODX section, I'm pretty sure testing the URI "bookingsystem.php" won't work since you would have already striped out the php extension by this point. This may or may not be related to your current issue, but something to keep in mind when testing, no "php" extension should make it to the MODX section of the file.

                NOTE: in MODX, you can simply set NO extension, and rather than use .html OR .php, it will automatically have nothing there and you won't need htaccess to strip it out. If you remove the file extension and someone types "thing.html" they will get the 404 page. It is usually faster to NOT have htaccess do stuff. So if you really don't want the html or php suffix, just take it out of MODX!

                I'm not sure I understand the issue in your last paragraph though. You said that the suffixes are removed and it returns the "correct pages", but then you're saying you can't redirect the pages to the short URLs. I don't follow.

                Can you give some examples of URLs that are not behaving, what you want to happen, and what is happening instead?

                One note. If you rewrite a URL, the part in the address bar stays the same, but content comes from the URL in the rewrite rule. Only if you use the redirect (like "[R=301]") will the page refresh with the different URL shown in the address bar.

                If you rewrite the short URL to show content from the long URL, but rewrite the long URL to redirect to the short URL, be careful of weird looping behavior.

                It sounds like you want "/register" to show content from "bookingsystem.php-long url". But you want "bookingsystem.php-long url" to do a complete redirect to "/register". Is this correct? You would need two rules to do this, one rewrite rule for showing content, and one for completely redirecting the page.

                Bottom line is, you can keep fiddling with this in htaccess, but just like MODX does, your bookingsystem should probably contain its own content handling so that you don't have to define all these "routes" in htaccess, but handle them in your php handler instead.

                These days, the fear of duplicate content is not so great. Google just guesses who the "real" content is for search results, but that is why you can specify the "canonical" URL in your pages. Please read: http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html

                  • 3749
                  • 24,544 Posts
                  Let me suggest this:

                  RewriteCond %{THE_REQUEST} (.*)\.php
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteRule ^(.*)\.php $1 [R=301,L,NE] 
                   
                  RewriteCond %{THE_REQUEST} (.*)\.html 
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteRule ^(.*)\.html $1 [R=301,L,NE]
                  
                  
                  # MODX The Friendly URLs part
                  ### RewriteCond %{REQUEST_URI} !=/bookingsystem.php
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteRule ^(.*)$ index.php?q=$1 [QSA]



                  The RewriteCond %{REQUEST_FILENAME} !-f line means that the rule will only execute if the filename is not found. That way, the rules shouldn't affect the booking system (making the first of your FURL rules unnecessary).

                  RewriteRule ^forgotpassword$ bookingsystem.php?controller=pjListings&action=pjActionForgotPassword [L]
                  RewriteRule ^register$ bookingsystem.php?controller=pjListings&action=pjActionRegister [L]
                  RewriteRule ^([^\.]+)$ $1.php [L]

                  For these rules to match, you'd have to have the beginning of a line (^) followed immediately by the search term, followed immediately by the end of the line ($). The right side also needs to be a full URL.

                  This form might be what you want:

                  RewriteRule forgotpassword http:yoursite.com/bookingsystem.php?controller=pjListings&action=pjActionForgotPassword [L]


                  You might also want to end it with [R=301,NC,L]

                  I would remove this line:

                  RewriteRule ^([^\.]+)$ $1.php [L]


                  Having a rule that removes .php and another rule that adds .php in the same .htaccess file is asking for trouble, wink and with the !-f lines, you shouldn't need it.



                    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