Mod Re-Write More info please

I'm hearing people telling me that Mod Re-Write is the next best thing since sliced bread. Can anyone that understands it please explain it to me and why I should be using it?

Thanks

Comments

  • NuvoNuvo Forum Leader VPS - Virtual Prince of the Server
    Mod_rewrite is an Apache module which lets you basically point URL's at different places using regular expressions.
    Because mod_rewrite is an Apache module, you'd have to make sure your host has it installed (most do and this site is already using it).
    It allows you to make more friendly URL's by doing things like pointing site.com/articles/content-creation at locations like site.com/index.php?mod=articles&art=content-creation.
    You do this by creating a file on your hosting account which contains the routing commands to point the better URL at the uglier location.
    Apache rewrite expressions aren't overly difficult to figure out, but they aren't as easy as something like Rails' internal routing.
    The only real issue with it is that relative URL paths within the page it routes to will try to load from site.com/my/non-existant-url/file.ext rather than site.com/path-to/file.ext, but this is easy to work around in your HTML.
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    problem is that it's not as easy to implement as one thinks... even if you're quite adept in writing rewrite code, you still need to have the script generate urls in a consistent manner with a pattern in it... otherwise you cannot rewrite anything... ;)
  • DeluxeNamesDeluxeNames Admin Administrator
  • JaredRitcheyJaredRitchey Moderator: Design Team Shared Hoster
    Boss man Bryant.

    An example of the kind of rewrites I get asked to do as taking a dynamic page and making it look like a static one for search engines and general url friendly link looking for lack of a better term.

    The best way to teach you is by example. So the scenario is like the one I did recently.

    +++
    The site owner had a static HTML site that was growing beyond his ability to manage as he would have to make changes to his entire site for a simple change which could mean the manual edit of hundreds of pages. He wanted to go to a DB driven site using Joomla and also have a WordPress Blog. However he had very high search engine rankings and was #1 in many places so changing URL's and file extensions would simply ruin all that. So I proposed the following changes which I'll outline here as I go.


    ########### The client purchased one of the cheaper SSL certificates from GoDaddy and at the time of his registration he used the WWW.domain for his key which means if somone typed https://domain.com it simply would not work. We needed to fix that first. ##############

    ### Lets change the NON WWW to WWW redirect
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^hisdomainname.com
    RewriteRule (.*) http://www.hisdomainname.com/$1 [R=301,L]

    #Next we make ExpiresActive which forces background image caching in Internet Explorer
    ExpiresActive On
    ExpiresDefault A18000
    ExpiresByType image/gif A2592000
    ExpiresByType image/jpeg A2592000
    ExpiresByType image/png A2592000

    ### Next here is a short example of how we deal with the rewrite from DB URLS to SEO friendly ones. The db link looks like
    http ://www .domainname .com /index.php?option=com_content&task=view&id=12

    Ok thats like trying to remember the GPS location to my home instead of just a simple address. So we want it to look like http://www .domainname.com / austin-rentals.php in order to index as the preferred link in PHP instead of his existing HTML version so we do the following;

    RewriteRule austin-rentals.php /index.php?option=com_content&task=view&id=12[L]

    ## when the [L] is encountered it essentially looks no further.

    ##Last we need to deal with the Re Directs so his OLD HTML pages will get properly redirected and INDEXED by the Search Engines as the PHP equivelents. We do the following

    RedirectMatch permanent ^/austin-rentals.html$ http: //www.domainname.com/austin-rentals.php

    #Now we have finally achieved what we were after. If a person trys to visit the old url of http://www.domainname.com/austin-rentals.html not only will they be redirected to the .PHP extension but will be directed to the fully database driven link which is truly http://www.domainname.com/index.php?option=com_content&task=view&id=12

    Thus the new CMS he is using to manage his site will be a painless NO LOSS transition from the original GIGANTIC hand edited code source.

    ~ Jared
    signature? whats a signature?
Sign In or Register to comment.