We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21136
    • 103 Posts
    Moved from: http://modxcms.com/forums/index.php/topic,22705.0.html

    Hello smiley

    This might be a strange request but I hope someone can help smiley

    I am using weblinks as containers and then the weblink redirects to an index page within the container...

    Don’t ask why but it was for SEO issues ... I started using this in early 9.5

    So an example of what happens is:

    Visitor hits "...com/folder-name/" and they will be redirected to "...com/folder-name/index.html"

    That works fine but the header generates a 301 redirect and now Google is giving me warnings that I have way too many 301’s and I need to fix or will be consequences :O

    It’s to late to go backwards because I have hundreds of pages indexed and don’t want to fall of the face of the planet.

    So how can I use mod_rewrite to report a 200 instead of a 301 ?

    Does anyone know the exact code to insert into the htaccess file?

    Regards,

    Ken Roberts
      • 31337
      • 258 Posts
      No you can’t. A 200 code means the file was served up fine. You’re redirecting to a new file, thus requiring a 301.

      The trick is to use something like mod_rewrite to rewrite the URL on the server side to serve up the proper file, rather than telling the client where the new file is.

        • 21136
        • 103 Posts
        Yes - I agree. That is what I was really asking. Sorry for not being clear. What mod_rewrite lines of code do I use?

        So if a visitor goes to "http://www.domain.com/folder-name/" and I need him to end up at "http://www.domain.com/folder-name/index.html", what mode_rewrite do I insert into my .htaccess file? And I assume I will need to do this for each folder that I need the server to serve up a different file.

        Can anyone give an example of how I might do this in the .htaccess file?

        Regards,

        Ken Roberts
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          So you have "empty" folder/documents, and you want someone who accesses one of these to actually get the first child of that folder? That’s what the FirstChildRedirect snippet is for.

          I use it all the time in multilanguage sites. I create top-level folder documents for each language, and that language’s home page is the first child. Then I have a language selection menu (or dropdown or whatever) using Wayfinder with a startId of 0 and a level of 1. That way when someone selects a language, he’s sent to that language’s home page.
            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
            • 21136
            • 103 Posts
            Thanks for the quick reply. I use firstchildredirect all the time too, but not for this issue.

            I need the server to "serve up" a different page so that the header reports a 200 and not a 301 from the server.

            As in my previous example, the visitor goes to "http://www.domain.com/folder-name/" the server needs to serve up "http://www.domain.com/folder-name/index.html".

            The issue is that Google has given me a warning that it doesn’t like the 301 that it currently receives when they go to the folder URL and then redirected (human review). They are giving me time to fix this before they start to whack my rankings. The site is a few years old and toooo many (hundreds) of high ranking pages to start restructuring.

            So this is why I was asking if someone could tell me the mod_rewrite lines to insert into my htaccess file that would accomplish this for the "redirect".

            I have 10 folders that I need mod_rewrite to serve up a different page:

            /folder-name/" -> /folder-name/index.html
            /folder-name1/" -> /folder-name1/index.html
            /folder-name2/" -> /folder-name2/index.html
            /folder-name3/" -> /folder-name3/index.html
            etc...

            My skills at mod_rewrite are almost none smiley

            Regards,

            Ken Roberts
              • 4310
              • 2,310 Posts
              Try adding a rule like this for each folder...
              RewriteRule ^folder-name/ folder-name/index\.html [R=301,L,NC]

              There’s probably a way to do one rule that works for all the folders.
              I’m assuming you have RewriteEngine On etc.
                • 21136
                • 103 Posts
                Yes - that is what I was looking for. But I do have a question about that line...

                You use "[R=301,L,NC]" in your example. Doesn’t that make it return a 301? (I need it to return a 200). Would I simply replace "200" where you have "301" ?

                Regards,

                Ken Roberts
                  • 4310
                  • 2,310 Posts
                  I don’t think you can use .htaccess to "cheat" the server into returning a 200 header.
                  At the end of the day the requested page was not found.
                  As far as I know, which isn’t very far, a permanent 301redirect via .htaccess shouldn’t be penalised by Google.
                    • 21136
                    • 103 Posts
                    Typically a 301 is what Google wants to see for a redirect. The issue is that they said I have too many 301 redirects because every folder returns a 301. Whether I use a weblink or firstchildredirect it returns a 301 and Google doesn’t like that for this situation.

                    Regards,

                    Ken Roberts
                      • 4310
                      • 2,310 Posts
                      What about creating the index.html page for each folder outside of MODx and putting it in the correct folder?
                      If you try to access the url http://yourdomain.com/your-folder/ it should automatically open the index.html page with no redirecting.