Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Help with 301 .htaccess

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #186847
    lprintz
    Participant

    Hello all!

    My client just signed on with Hubspot and they created a new blog for him and I need help with the .htaccess redirect

    Old – http://www.eaglerockfinancial.net/blog/
    New – http://blog.eaglerockfinancial.net/financial

    My challenge is…I’d like to set it up as a ‘wild card’ so that I don’t need to redirect ALL his articles. The way the URLs are set up tells me this may be possible I hope. Here’s an example of an article…notice the similarity…

    Old – http://www.eaglerockfinancial.net/blog/financial-life-track-divorce/
    New – http://blog.eaglerockfinancial.net/financial/blog/financial-life-track-divorce

    Can this be done?

    Thanks so much!

    Len

    #186850
    shaneisme
    Participant

    I’m not sure if you can do this via .htaccess, but you can probably do this with code. For instance, in PHP, you can first collect the URL and use that as a variable to parse with whatever logic you need and then set the header to that new page with a 301.

    You can actually use .htaccess to force all requests into a main index.php file that will handle the requests. Almost like a front-controller.

    #186862
    __
    Participant

    It could be done with mod_rewrite, but it would require hard redirects (because they are different domains).

    #186899
    lprintz
    Participant

    Thanks for all your responses!

    Chris, to answer your question, no idea! :)

    This is just how hubspot set up their new blog…I thought it was odd as well

    So there isn’t a way to do something like…

    http://www.eaglerockfinancial.net/blog/* redirects to
    http://blog.eaglerockfinancial.net/financial/blog/*

    I was hoping but didn’t know the syntax or how to set that up in .htaccess

    Len

    #186900
    lprintz
    Participant

    I just found this in a forum…this may be what I’m looking for but just need help on exactly how to set up in .htaccess:

    “To use wildcards, put an asterisk after the folder name that you want to redirect.

    Request: /old-folder/*
    Destination: http://domain.com/redirect-everything-here/

    Whatcha think?

    #186905
    __
    Participant

    mod_rewrite is based on regular expressions, not shell pattern matching. “*” is a quantifier that means “zero or more” —so “/*” means “match zero or more slashes.” It would match “/”, “//”, “//////////”, etc., or even “”.

    You would need to explain the relationships between the two URL formats more clearly, but assuming they are consistent, you could do something like

    RewriteRule ^financial/blog/(.*)$ http://blog.eaglerockfinancial.net/financial/$1 [NC,R=301]
    
    #186916
    lprintz
    Participant

    Sorry for the confusion…notice that ‘blog/article-name’ is the same…just the first part of the URL changed. That’s why I was looking for some sort of ‘wildcard’ solution

    Old – http://www.eaglerockfinancial.net/blog/financial-life-track-divorce/
    New – http://blog.eaglerockfinancial.net/financial/blog/financial-life-track-divorce

    #186966
    __
    Participant

    Ahh — yeah, your examples have been a bit inconsistent. It’s not a big thing to change. Again, there’s no “wildcard” in regex. You can do .* (as I did above), which means “zero or more of any character”.*

    * except a newline, but that isn’t particularly important with URLs.

    But, let me ask you this: do you want to redirect every URL? or only the blog entries? From your description, I would assume the latter.

    And I would like to echo chrisburton’s confusion over the repetitiveness of new URL structure. Have you thought about fixing it?

    #186975
    lprintz
    Participant

    Howdy!

    Sorry for the confusion

    I only want to redirect the blog entries so only the first part of the URL is changing which definitely needs to include /blog/

    I agree with the bad URL structure of the new blog but, as I responded to Chris, this was done by a 3rd party (Hubspot) so I don’t have any control over it

    Sooooo….can this be done? If so, could you shoot me the way I should set up in .htaccess?

    Again, thanks so much for your response!

    Len

    #187013
    __
    Participant

    Sooooo….can this be done? If so, could you shoot me the way I should set up in .htaccess?

    Are you asking me to do it for you? If so, we should talk price. Or, do you want to figure out how to do it yourself? I’d be happy to help you learn if you come across something you can’t solve on your own.

    If you want to learn, the example I posted above is a good place for you to start. You should also look at the mod_rewrite page in the Apache Manual. And there are lots of beginner tutorials around the web. If you have questions, please ask.

    I agree with the bad URL structure …this was done by a 3rd party (Hubspot) so I don’t have any control over it

    What I meant to ask was if you were interested in rewriting the new URLs also, so they could be more “friendly.”

Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘Other’ is closed to new topics and replies.