Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2012, 02:34 AM   PM User | #1
spacepoet
New Coder

 
Join Date: Jul 2006
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
spacepoet is an unknown quantity at this point
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.
spacepoet is offline   Reply With Quote
Old 02-12-2012, 04:44 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 02-12-2012, 07:08 PM   PM User | #3
spacepoet
New Coder

 
Join Date: Jul 2006
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
spacepoet is an unknown quantity at this point
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 ??
spacepoet is offline   Reply With Quote
Old 02-13-2012, 02:36 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 02-13-2012, 04:24 PM   PM User | #5
spacepoet
New Coder

 
Join Date: Jul 2006
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
spacepoet is an unknown quantity at this point
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.
spacepoet is offline   Reply With Quote
Old 02-13-2012, 05:02 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 02-13-2012, 05:11 PM   PM User | #7
spacepoet
New Coder

 
Join Date: Jul 2006
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
spacepoet is an unknown quantity at this point
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.
spacepoet is offline   Reply With Quote
Old 02-13-2012, 11:06 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 02-15-2012, 12:12 AM   PM User | #9
spacepoet
New Coder

 
Join Date: Jul 2006
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
spacepoet is an unknown quantity at this point
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 ??
spacepoet is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:36 PM.


Advertisement
Log in to turn off these ads.