1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to Add Multiple Redirects to httpd.conf in MAMP PRO 4.1.1

Discussion in 'Apache' started by WordWeaver777, Feb 27, 2017.

  1. #1
    Hello again,
    SEMrush
    I tried posting this same message multiple times yesterday, but was unable to, and ended up frustrated, because your forum software has a problem with a redirect code snippet I include in my message, even though I was sure to enclose in the correct "code" and "/code" brackets.

    So, I am going to try one more time, but this time, by actually uploading my full message as an uploaded file. I hope it works this time, because I don't know what else to do, and I cannot figure out this redirect business on my own.
     

    Attached Files:

    WordWeaver777, Feb 27, 2017 IP
    SEMrush
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Just put the code inside [ code ] [ /code ] tags (remove the spaces) - it works just fine.

    
    ServerAdmin wordweaver777@gmail.com
    ServerName billkochman.com
    RedirectMatch 301 (.*) https://www.billkochman.com$1
    
    Code (markup):
    As for the extra domains, you can just add a ServerAlias right after the ServerName with the extra domains
     
    PoPSiCLe, Feb 27, 2017 IP
  3. WordWeaver777

    WordWeaver777 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Thank you for your reply, PopSiCLE, but as I already stated in my previous message, even when I enclose that snippet between [ code ] and [ /code ], this forum software was still recognizing the redirect in my snippet, was repeatedly sending me a warning regarding including a redirect in my message, and would not let me post my message.

    In fact, even when I quote your message where you include my httpd.conf directives, this forum software keeps giving me the same error:

    "The following error occurred:
    ______ is a redirect to ______ (use the destination URL instead)."

    At any rate, following your suggestion, I went to the Apache website to learn exactly how to use a ServerAlias, being as I had never done it before. As you can tell by my status here, I am a total greenhorn pretty much when it comes to configuring httpd.conf files.

    Anyway, I added these three lines right after ServerName billkochman.com, and all three are working properly:

    ServerAlias armageddonbbs.com
    ServerAlias endtimeprophecy.net
    ServerAlias endtimeprophecy.org

    As I explained in that uploaded text file, the ONLY thing that is not working to my liking, is that if someone uses my domain name without the www, they are redirected to the https version of my site without the www, whereas I really want them to be redirected to https with the www, being as that is the preferred domain I have set up in the Google Search Console.

    Is there some way I can tweak the directives I am now using so that it is also redirected to the secure version of www, instead of to just the domain name without the www?

    I am sorry if this seems a little confusing, but this forum software is just not cooperating with me. I can't use both URL versions of my site in my message, because it keeps throwing me that same error message that I mentioned above.

    Thank you for your patience and assistance. I appreciate it.
     
    WordWeaver777, Feb 27, 2017 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    My tip (courtesy of this thread on stack overflow: http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www)

    First you set up one VirtualHost with this content:

    
    <VirtualHost *:80>
    ServerName example.com
    Redirect permanent / http://www.example.com/
    </VirtualHost>
    
    Code (markup):
    You can add the serveraliases in that rule as well, I think

    Then you have ANOTHER VirtualHost right after that one, where the ServerName is set to the domain with the www in front.

    That should make sure that they all redirect to the www-domain, and then you can add the other rules into that second VirtualHost.
     
    PoPSiCLe, Feb 28, 2017 IP
  5. WordWeaver777

    WordWeaver777 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    Thank you again. Just to avoid these forum software hassles I am having -- could your ease with posting [ code ] and [ /code ] messages be due to the fact that you are at a much higher level than I? -- let me respond in another text file and upload it here. Then you can let me know how you think I should proceed. Your current suggestion is not working.
     

    Attached Files:

    WordWeaver777, Feb 28, 2017 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Nah, the level doesn't matter. As for the code, sorry my suggestion didn't work. It seems everything works fine, the other domains as well, just not, as you said, the non-www version - it stays non-www. You might find something helpful here: https://www.internetmarketingninjas.com/blog/search-engine-optimization/301-redirects/

    It seems like this should work (granted, in a .htaccess-file, but it should work with perhaps minor rewrites):
    
    RewriteCond %{HTTP_HOST} ^xyz\.com [NC]
    RewriteRule ^(.*)$ http://www.xyz.com/$1 [L,R=301]
    
    Code (markup):
    You could try that last one only, first - ie. the ^(.*)$ instead of the (.*) you have now.
     
    PoPSiCLe, Mar 1, 2017 IP
  7. WordWeaver777

    WordWeaver777 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    Well, PoPSiCLe, using my current directives, but changing (.*) to ^(.*)$ instead did not help. As with my current code, everything works with your suggestion, except for the non-www URL. It still goes to the secure version of non-www, and not to the secure version of www.

    Regarding using .htaccess files to do a lot of this redirecting, I don't understand why so many so-called "SEO experts" continue to recommend that approach.

    In other words, everything I have read on the official Apache site seems to discourage this, and instead encourages placing such directives in the httpd.conf file, as the official way to do things.

    This seems similar to the online battle I have recently discovered occurring between, again, so-called "SEO experts", where some are adamant about using relative URLs, while others are equally insistent that we should use absolute URLs. Each camp offers their list of reasons why we less-informed people should accept theirs as the more valid position. I find it all very confusing.

    But as to this lingering stubborn issue, I just don't have the knowledge or experience to get that one redirect working properly. So, unless someone else here offers a real fix, I suppose I am done here.
     
    WordWeaver777, Mar 1, 2017 IP
  8. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #8
    Oh, I wasn't meaning you should use .htaccess, just that the example I provided was meant for .htaccess, not for httpd.conf - usually, if you have access to the configuration files, it's always better to place such things there, instead of having to be parsed on the server. But you tried the code-example above as well? That SHOULD work, as long as you replace the content with your own domain of course. It would work on .htaccess, I think it should work on httpd.conf too.
     
    PoPSiCLe, Mar 1, 2017 IP
  9. WordWeaver777

    WordWeaver777 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #9
    Oh, don't worry. I understood that you weren't suggesting that I use the code in the virtual host's .htacess file, rather, that I should try to implement it in the httpd.conf file instead. I was merely making a side observation, just as I did with the relative/absolute URL battle thing.

    As I said, my problem is that I am such a greenhorn with all of this stuff, I don't actually know or understand how to actually implement it in my httpd.conf file. I don't know the correct syntax, what parts I should change, what parts I should leave untouched, etc.

    Over the past week, I have viewed many different coding examples online, all of which have failed to work for me, except for the one which I have already shown you works for me about 80%, in the one text file that I uploaded here.

    In fact, even that did not take care of the other three domains, until you mentioned the use of ServerAliases to me. The name alone suggests what they are, but I still had to go to the Apache site, in order to find out exactly what they are, what they look like, and exactly how to implement them with the RedirectRematch code that I already had working for me. Thankfully, that one was easier for me to figure out.

    But what you are suggesting now requires more detailed help in order for me to grasp it, and know how to actually implement it, instead of the code I am now using.

    Obviously, I know that I need to replace xyz with my domain, billkochman. But it still leaves me confused regarding all the rest.

    I read that page you suggested, so I also know that this new code you suggest is non-case-specific, and that it is also a permanent redirect, similar to what I am now using. However, I do not see any https in there, so I don't see how it redirects any or all of my traffic to my
    https://www
    Code (markup):
    URL. Likewise, there is nothing in there which hints to me -- even if it is staring me in the face -- how to add those three other domains to that code so that all traffic to them is also redirected to my
    https://www
    Code (markup):
    URL.

    So if you can help me out further here, I would be most appreciative.

    You see, this is why those series of "Dummies" books are great. They assume that the end user really does know nothing. They spell out everything clearly. That is what I need at this stage.

    Thanks again!

    PS: GGGRRRrrr . . . See! I even had to enclose those two simple things in the code tags, because this forum software was throwing me an error code otherwise, and would not allow me to post.

    So why does it allow me to use the code tags with those two, but not with more complicated stuff?

    The answer is clear! It is biased against greenhorns! :) :p
     
    WordWeaver777, Mar 1, 2017 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Could you provide the exact code of the setup you have now? The httpd.conf, I mean? Just post it as a text-file, if the [ code ] -tags won't work for you. Or just paste it on pastebin or something (just make sure there is nothing that shouldn't be publicly available on there).
     
    PoPSiCLe, Mar 1, 2017 IP
  11. WordWeaver777

    WordWeaver777 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #11
    
    ServerAdmin wordweaver777@gmail.com
    ServerName billkochman.com
    ServerAlias armageddonbbs.com
    ServerAlias endtimeprophecy.net
    ServerAlias endtimeprophecy.org
    RedirectMatch 301 (.*) https://www.billkochman.com$1
    
    Code (markup):
    I don't know why, but just now the forum allowed me to use the [ code] [ /code ] tags.

    Please note that all of this placed right before the following, as per the MAMP PRO developer's instructions:

    
    </VirtualHost>
    MAMP_VirtualHost_iteration_end_MAMP
    MAMP_VirtualHosts_end_MAMP
    
    Code (markup):
     
    WordWeaver777, Mar 1, 2017 IP
  12. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #12
    Okay. In theory, this should work:

    
    ServerAdmin wordweaver777@gmail.com
    ServerName billkochman.com
    ServerAlias armageddonbbs.com
    ServerAlias endtimeprophecy.net
    ServerAlias endtimeprophecy.org
    RedirectMatch 301 (.*) https://www.billkochman.com$1
    RewriteCond %{HTTP_HOST} ^billkochman\.com [NC]
    RewriteRule ^(.*)$ https://www.billkochman.com/$1 [L,R=301]
    
    Code (markup):
    You might need to wrap the last two inside a directory wrapper, like this:
    
    <Directory>
    RewriteCond %{HTTP_HOST} ^billkochman\.com [NC]
    RewriteRule ^(.*)$ https://www.billkochman.com/$1 [L,R=301]
    </Directory>
    
    Code (markup):
    Could you test that, and see if it makes any difference?
     
    PoPSiCLe, Mar 2, 2017 IP
  13. WordWeaver777

    WordWeaver777 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #13
    Sad to say, but neither is working. With the first one, all of the other redirects continue to work fine; but the non-secure non-www to secure www still does not work.

    With the second one with the directory tags, Apache refuses to even start up.

    So I am back again to using my original code.
     
    WordWeaver777, Mar 2, 2017 IP