SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Switching a few sites from .NET to PHP. Need a few pointers on .htaccess files

    Right now I have a few sites that use ASP.NET MVC and while I do enjoy the routing structure I hate a lot of Windows Server works (and also how it sometimes doesn't work for no reason). I've had enough of running two servers, one with Windows and one with Apache and I'm jumping ship to go strictly PHP. I'm abandoning my CMS and going to use Wordpress and let someone else handle the backend.

    Right now I have the URL structure as "domain/(controller)/(action)" layout. Your basic MVC structure.

    I have it set so that "domain/Page/(pageTitle)" displays the pages and "domain/Article/(articleTitle)" (Page and Article are literals that target the controllers as part of the URL while the items in parentheses are variables). The way wordpress works is simply "domain/(pageOrArticleTitle)" but since I've been ranking #1 on google for my hometown I don't really want to mess that up and have google have 404s. Can I have the pages and articles forward using the .htaccess file and send a 301 for the original URL structures and forward to the new URL so that google doesn't drop me in the results?

    Any idea how to handle this? Any advice is very welcome.

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Why PHP? If you were to go with something more modern, say, Python using flask, you can have routing too: http://flask.pocoo.org/docs/quickstart/#routing

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,605
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Pennsyltucky? Isn't that WV?

    In answer to your question, mod_rewrite is VERY powerful because it uses a regex engine to capture information and use it to redirect. However, nowhere in your post did I see that you were retaining the same data in your links in your new structure to allow capturing variables and using them to redirect.

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    That said, you have two options: Redesign your new site's links to retain some/all of the link information from the old website OR use a RewriteMap (probably use a "handler file" for the redirect) to redirect EACH of the old pages to their corresponding pages in the new website (with permanent redirections so you don't have to go through this painful experience again).

    "Speficity!" There, I said it again. More information about your links (that they can be used in redirections) or not; how many redirections (pages) are being moved; etc., the better the answer you'll get.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,154
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    The Apache documentation considers this a scenario where you should not use mod_rewrite.

    Redirect and RedirectMatch were designed for scenarios exactly like this one.
    "First make it work. Then make it better."

  5. #5
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the information. It looks like using "RedirectPermanent URL-path URL" is what I'm looking for. Seems simple enough.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •