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.

Need help with writing htaccess rewrite rule

Discussion in 'Apache' started by serlak2007, Feb 21, 2014.

  1. #1
    Hi Everyone,

    I'm trying to change url structure so instead of /default/category/product.html it would show /category/product.html

    With this line I've managed to do it on my personal blog

    RedirectMatch 301 /default/(.*) //$1

    But when I've implemented it on a customers Magento site it started showing double slashes like this //category/product.html and the whole template just collapsed :). Anybody knows why this solution doesn't work?

    Huge Thanks,
    Sergey
     
    Solved! View solution.
    serlak2007, Feb 21, 2014 IP
  2. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #2
    Configuration->Web->URL Options-> Change to No on Add store code to URL

    That is the only reason I can think /default is there in the first place. That, or someone built it wrong out of the gate.

    hope that helps,
    Nigel
     
    Nigel Lew, Feb 21, 2014 IP
  3. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #3
    Thanks for replying. I do know how to remove /default/ from url, the issue is what to do next. The plan is once I change that option to "no" all pages crawled by google will become 404s. So I need to create a rewrite rule , and the one mentioned before did work on my blog but didn't work on Magento. It added extra "/" after domain, not sure why it did so. I tried to remove 1 slash from

    RedirectMatch 301 /default/(.*) //$1

    so it became RedirectMatch 301 /default/(.*) /$1

    And apparently it messed up layout.
     
    serlak2007, Feb 21, 2014 IP
  4. #4
    hmph. Well you are correct that it should not have 2 // in front of $1 however, that is mod_alias not rewrite so try this perhaps.

    RewriteEngine On
    RewriteRule ^default/(.*)$ /$1 [L,R=301,NC]

    let me know if that works. I am not an apache expert so I typically have to try a few things to flesh that out correctly.

    And actually, you wont need RewriteEngine On either depending on where you put that but you likely should put it right below rewrite base.

    Always remember to flush the cache and run the indexer as well. Especially the latter because urls are governed by the indexer but sometimes Mage won't tell you that you have to run it. You may have already fixed it.
    Nigel
     
    Nigel Lew, Feb 21, 2014 IP
  5. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #5
    Thanks a lot, I'll try your solution later today, when there will be no people on the site.
     
    serlak2007, Feb 21, 2014 IP
  6. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #6
    Yea, I had a question about the indexer. Is it really necessary to run it after I do such global changes?
     
    serlak2007, Feb 21, 2014 IP
  7. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #7
    "Always remember to flush the cache and run the indexer as well. Especially the latter because urls are governed by the indexer but sometimes Mage won't tell you that you have to run it. You may have already fixed it."

    Just a quick note that part. It looks like I was editing my post at the time to add that.

    N.
     
    Nigel Lew, Feb 21, 2014 IP
  8. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #8
    Yep, sure is. SEO urls are in the indexer list so it may not have actually changed on the front end until you do so.

    N.
     
    Nigel Lew, Feb 21, 2014 IP
  9. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #9
    Huge thanks!

    So let me see if I got it right.

    1. Change URL Option to "no"
    2. Implement redirect rule in htaccess
    3. Run indexer.

    Question - after I implement redirect rule, will the site work without running indexer? The reason why I ask is that maybe my solution was correct and I just didn't run the indexer and as a result the design layout stopped working properly.
     
    serlak2007, Feb 21, 2014 IP
  10. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #10
    I've just tried

    RewriteRule ^default/(.*)$ /$1 [L,R=301,NC]

    on my blog and it only redirects url/default/ page and pages like url/default/samplepage.html return 404 :(
     
    serlak2007, Feb 21, 2014 IP
  11. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #11
    In theory, yes. The htaccess rule may have been correct. Set it to no, then run the indexer first to clear old old stuff in magento's url cache.

    That should keep the template in order.
    Magento is a fickle beast sometimes but that should do it. If not, I am happy to take a look at it. I was messing with magento on the 1.x branch before it would actually install correctly.

    Sometimes the server has some weird cache stuff going on or cloud flare will make the site take a while to update changes as well. I learned that the hard way a few days ago lol..

    Nigel
     
    Nigel Lew, Feb 21, 2014 IP
  12. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #12
    Nigel Lew, Feb 21, 2014 IP
  13. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #13
    I'll try it later today. I've been having major problems with this Magento CMS and site owner's developers are the nastiest, uncooperative people I've seen so far in my SEO career. I've also seen some weird stuff going on in URL Rewrite section, some weird system rewrites just appear out of a blue and I don't know how to figure out who posts them.....
     
    serlak2007, Feb 21, 2014 IP
  14. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #14
    pfft figures. They likely want to charge the guy a truckload of cash to resolve simple stuff. I am happy to lend a hand if need be. I may not be around until tomorrow again. 7pm here. Just drop me a note if you want a quick bit of help though. I am happy to help you fix that for free so you can get to work.

    That sort of thing bothers me. Folks should not bill people for stuff like that if they were hired to do the entire thing.

    Nigel
     
    Nigel Lew, Feb 21, 2014 IP
  15. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #15
    :) It is even more outrageous, since I've asked for access to hosting owner of developing company acts like every problem with the website is now my responsibility.... Funny guy...

    Thanks for the link I hope the solution will work. What are your rates BTW, if I'll convince the owner to change developers I could refer your services.
     
    serlak2007, Feb 21, 2014 IP
  16. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #16
    My rates depend entirely on what I have to do really but I would fix that for free.

    The devs frankly sound like a bunch of assholes. You are not exactly trying to build a rocket here.

    I am typically doing the SEO as well but if some SEO fellow asked me for some login info or how to resolve that I would hop in there in there and fix it for him in under an hour. The situation you describe is not the devs looking out for the client, just themselves apparently.

    Nigel
     
    Nigel Lew, Feb 21, 2014 IP
  17. serlak2007

    serlak2007 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #17
    Huge Thanks Nigel! Looks like your solution worked. I didn't do reindexing because index management page doesn't show that it is required and it works good without reindexing :).
     
    serlak2007, Feb 22, 2014 IP
  18. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    405
    Best Answers:
    21
    Trophy Points:
    295
    #18
    Awesome!. Glad I could be of assistance.

    Nigel
     
    Nigel Lew, Feb 22, 2014 IP