Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Mod rewrite ??

  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    62
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Mod rewrite ??

    Hello:

    I wanted to see if it is possible - or how it is possible - to use a .htaccess file to do mod re-writing for more search engine friendly URLs.

    I have a zipcode database I am using, and wanted to see how I can dynamically re-write a URL like this:
    Code:
    www.MyWebsite.com/myCities.php?zip_id=35093
    to a URL like this:
    Code:
    www.MyWebsite.com/Antonito-Colorado-81120
    The data is in one table called "zipcodes" and the "zip_id" is used to pull out the city, state, and zipcode on the pages.

    All I know how to do it this:
    Code:
    RewriteEngine on
    RewriteRule ^$ Page.php
    Where, it makes the URL go to Page.php ...

    Can someone get me started on this? Not sure what direction I should be looking...

    Thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This hasn't a thing to do with PHP, moving to Apache configurations.
    What are you trying to capture off of that rewrite url? The mappings to match between the zip_id and the number in the phrased URL.

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    62
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Hi:

    Yes, I think that is what I want .. not sure as it's new to me ..

    I basically want to write keywords into the URL vs. having the query string.

    It currently shows like this:
    Code:
    www.MyWebsite.com/myCities.php?zip_id=35093
    So, I wanted to see if it is possible to use the "zip_id" to pull the city, state, and zipcode out of the database, and the re-write the URL to something like this:

    Code:
    www.MyWebsite.com/Antonito-Colorado-81120
    Can this be done ??

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Wait. Do you mean to go the other way so that it changes the querystring links into phrased url? Redirect would work, but I don't think that takes a pattern. And rewrite doesn't redirect the url. So that would require changing your links to match what you want.

  • #5
    New Coder
    Join Date
    Jul 2006
    Posts
    62
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Yes

    Hi. yes - i want the querystring to become a phrased url.

    i want to do it dynamically, since its 1000's of zipcodes coming from a database.

    is this possible?


    sorry if i don't understand mod rewriting - its new to me and i'm a bit confused what can be done with it.

    thanks for the help.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by spacepoet View Post
    Hi. yes - i want the querystring to become a phrased url.

    i want to do it dynamically, since its 1000's of zipcodes coming from a database.

    is this possible?


    sorry if i don't understand mod rewriting - its new to me and i'm a bit confused what can be done with it.

    thanks for the help.
    You'll use PHP after all. Reformat your URL's to match what you want.

  • #7
    New Coder
    Join Date
    Jul 2006
    Posts
    62
    Thanks
    7
    Thanked 0 Times in 0 Posts

    how?

    Hi.

    thanks for the reply ... but how?

    can you show me some sample code?

    thats where im stuck - i dont know how to do it or what type of code to look for.

    thank you.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    When you have a url that is in the format of /page.php?id=someid, you reformat this link to match how you want it to show. Assuming you have a mod_rewrite in place, it will redirect as needed.
    I'd suggest writing a link manager for this to perform the replacement only if mod_rewrite is enabled. Otherwise its a search and replace.

  • #9
    New Coder
    Join Date
    Jul 2006
    Posts
    62
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Ok .. still can't get it to work .. :(

    Hi:

    I am trying to do this 2 different ways, but no luck ..
    - I am on a GoDaddy Linux/Apache server
    - I have the site in a subfolder within the root, and that is where I am addding the .htaccess file, and the other files.

    So ..

    This is my .htaccess file
    Code:
    # Mod Rewrite
    Options FollowSymLinks
    Options -MultiViews
    RewriteEngine on
    
    RewriteRule ^([^/.]+)/?$ /Promotional.Products.State.Listing.php?abbr_state=$1&full_state=$2 [L]
    
    RewriteRule   ^Promotional.Products.State.Listing.php?abbr_state=AL&full_state=Alabama$  Promotional-Products-Alabama-Promo-Items-Alabama.html
    I am trying to get it to work 1 of 2 ways.

    I changed the first link to be this:
    Code:
    <a href=\"Promotional.Products.State.Listing/Promotional-Products-Alabama-Promo-Items-Alabama.html\">Alabama</a>
    I also have the other set of code in the .htaccess file to try and write:
    Code:
    <a href=\"Promotional.Products.State.Listing.php?abbr_state=AK&full_state=Alaska\">Alaska</a>
    to

    Code:
    <a href=\"Promotional.Products.State.Listing/AK/Alaska">Alaska</a>
    (Something like that) but it does not seems to be working.

    Maybe GoDaddy servers take awhile to update (but that would seem odd).

    What am I missing ??


  •  

    Posting Permissions

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