SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to use .htaccess and database

    I'm playing with the .htaccess and I'm wondering if there is a way to take a URL like this one:

    http://parttimejobsin.us/cities/index.php?id=1000


    (This URL points to a php file that queries a data base. The data base for that has a column for "id" and a column for "sef". In this case "id" = "1000" and "sef" = "prescott-valley-arizona")


    Can .htaccess be used to rewrite URL to:
    http://parttimejobsin.us/cities/pres...y-arizona.html

    if so how? any help will be appreciated

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    What CMS are you using?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the section of the site that I want to do this for, I am not using any CMS. I'm just coding with MySQL and PHP

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    JS,

    The answer is a resounding YES! (But ONLY if you have access to the server and/or VirtualHost config file.) The mod_rewrite statement is RewriteMap which is only available via those config files, not .htaccess.

    Don't despair, though, as you can use your own "redirect" (PHP) script to do the same thing so long as there is no output before a header("location:yadda-yadda"); command.

    Regards,

    DK

    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

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK,

    Thanks for the response. Sounds like you've got some real experience in this.

    I'm not entirely sure I have access to the server in that way nor am I sure whether I have access to the VirtualHost config file. I am on a reseller account through HostGator and they use CPanel/WHM, but aside from setting up new hosting accounts I have never played with any of the settings.

    I do not have an output command before the header. So if it turns out that I don't have access to the Virtual Host config file, then the redirect script you're suggesting may have to be my only alternative.

    Can you point me in the tight direction? Cuz I'm not entirely sure what I should do from here.

    JS

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    JS,

    If you're on a hosted account (and NOT a dedicated server), you should NOT have access to the configuration files (because even a minor syntax error can bring the server down for EVERYONE).

    That said, I'm sure that you're stuck with the PHP solution which is very nearly identical to the RewriteMap solution (except that it's ALL done with PHP, not a PHP "program" executed by mod_rewrite; the difference is in returning the header() rather than a simple text output for the redirection by mod_rewrite).

    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


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
  •