We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4429
    • 429 Posts
    I have a static site with a landing page of index.html I have taken this and installed Modx.

    I would like to do a 301 redirect from index.html to index.php (the modx version).

    The problem is this site is on a Windows server and I have no access to the control panel.

    What is the best way of going about this?
      • 5689
      • 289 Posts
      You can use .htaccess if mod_rewrite is setup on the server. If you don’t know, just try and see if this works.

      You may already know how to use mod_rewrite, but I’ll write as if you don’t just in case. smiley

      Create a text file in the same folder as index.html and name it ".htaccess" (no quotes, obviously; make sure you don’t put .txt on the end). The paste this code into the file and save.

      RewriteEngine On
      RewriteBase /
      
      RewriteRule ^(index.html)?$ index.php [R=301,L]


      This will redirect any calls to either the root of the site (since this automatically calls index.html anyway) or to index.html itself to index.php, and any query strings are appended by default.

      Would it not be easier to just delete index.html, though? Or does your server not automatically choose index.php as the default even if index.html doesn’t exist? I’m using Hostmonster for hosting, and their server (Linux, though) is set to first look for index.html, and if that doesn’t exist, it looks for index.php. Yours may be set up the same, so I’d try renaming index.html to something like old.html just to see if your server finds index.php by itself. Otherwise definitely try the method above with a .htaccess file.

      Hope this helps!

      Edit: I was thinking more about this, and using a .htaccess file might be overkill. First make sure the server won’t find index.php on its own like I described, and then try this. Simply put the following meta tag in the <head> section of index.html.

      <meta http-equiv="REFRESH" content="0;url=index.php">


      The only disadvantage to this method seems to be that the query string is not saved, so if somebody goes to www.yoursite.com/?page=0 (random example), they will get to index.php, but the query string will be lost.
        I&#39;m learning more about MODx all the time and loving it.
        • 4429
        • 429 Posts
        The server is not parsing the .htacess file, apparently the host will only allow this on dedicated boxes.

        I wanted to redirect rather than just delete the .html in case users had bookmarks, the site has over 5,000 visitors per month. Additionally I didn’t want to lose any page rankings.
          • 33372
          • 1,611 Posts
          Personally, if I couldn’t get mod_rewrite or something similar working I would just put a PHP header redirect in index.html
          <?php
          
          header('HTTP/1.1 301 Moved Permanently');
          
          header("Location: http://www.yourserver.com/");
          
          exit;
          
          ?>
          
          

          If for some reason you need/want the index.php at the end of your home page URL, add it to the Location line (but if your server is setup to default to index.php, you shouldn’t need that).
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Only problem with that is that .html files can’t have php code in them, unless the server is configured to run .html files through the php engine...
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 33372
              • 1,611 Posts
              Quote from: sottwell at Jul 22, 2009, 11:09 AM

              Only problem with that is that .html files can’t have php code in them, unless the server is configured to run .html files through the php engine...
              Right. Many servers are configured to parse PHP code in .html files, so give it a try. If yours isn’t, then you really need to talk to your server admins and figure out what sort of URL rewriting capabilities it has. If you can’t rewrite URLs and also can’t change any server configs, you need a new server. If you can’t use FURLs then you have more SEO issues to worry about than just your index.html file.
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 5689
                • 289 Posts
                There’s another problem with that as well. If you redirect to the root, you’re still going to get index.html. tongue

                Edit: I suppose this isn’t true if the default is index.php, but I’ve been assuming it isn’t.
                  I&#39;m learning more about MODx all the time and loving it.
                  • 4429
                  • 429 Posts
                  Well the server doesn’t parse html through the php engine, so just have to make to with a meta redirect for the time being. Thanks
                    • 33372
                    • 1,611 Posts
                    Search engines won’t be happy with your meta redirect (and they’d certainly prefer FURLs for the new URLs as well).
                      "Things are not what they appear to be; nor are they otherwise." - Buddha

                      "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                      • 5689
                      • 289 Posts
                      He doesn’t have much of a choice, though. If he doesn’t want to risk have a bunch of people with bookmarks to the site get 404s, and none of the things we mentioned work on his server, I don’t know what else he could do. :\
                        I&#39;m learning more about MODx all the time and loving it.