Forum Moderators: coopster & phranque

Message Too Old, No Replies

renaming dynamic url pages

         

iknowkevin

3:28 am on May 30, 2008 (gmt 0)

10+ Year Member



I have a database that allows me to create searches that pruduce results from my database. Example of a search result:

http://www.example.com/mls.html?subdivision=MAJESTIC%20BEACH%20TOWERS
&subdivision=MAJESTIC%20BEACH%20TOWERS%20PHASE%20I
&subdivision=MAJESTIC%20BEACH%20TOWERS%20PHASE%20II&search=Search

The issue is that the "mls.html?subdivision" or "?" is causing the search engins not to index the links from this page. How do you create a script that would allow me to substatute or rename the search result URL while still calling for the same results?

Additionally, how do I write a script that will dynamically rename the search result url's with fields in my database? An example would be to rename:
http://www.example.com/mls.html?mls_acct=382327

My database has fields like:
Subdivision
City
Property_type
Address

to http://www.example.com/"City"_"first_subdevision"_"property_type"_"address".html

[edited by: tedster at 4:24 am (utc) on May 30, 2008]
[edit reason] use example.com, and add line breaks to long url [/edit]

chorny

6:38 pm on May 30, 2008 (gmt 0)

10+ Year Member



Did you tried Catalyst framework? It can be used for this purpose.
Or CGI::Application with CGI::Application::Plugin::ActionDispatch.

In general there is environment variable PATH_INFO or others means to do this.

rocknbil

10:39 pm on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard iknowkevin. there is a simple answer to this: mod_rewrite.

However, it sounds like you might make the first mistake most people make with mod_rewrite, and get it backwards. Its common to think you'll be changing some complicated query string to a simple URL.

The truth is you work in exactly the opposite way.

This is what allows your script to keep functioning for **BOTH** your complex URL's and the serp-happy ones.

Once in place, you begin putting these links on your pages:

<a href="/City-first-subdivision-property-type-address">City; Subdiv, Prop Type</a>

Mod rewrite redirects it to your perl or php script. The way I do it is I have these URL's stored in a DB. If I detect a / after the domain name, I take everything after the domain name and see if it's a URL I have stored. To simplify:

mydomain.com/my-product

(split it up, then)

select prod_id from prod_urls where url like '%my-product%';

If this returns an ID, my script carries on as usual:

$qs{'pid'}=$whatever_result_was

products.cgi?pid=$qs{'pid'}

How you get here is simple. You make sure those URL's, or directories, do not exist on your site. Then in your domain level .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cgi-bin/products.cgi [L]

What this says is "if it's not a file and it's not a directory, send it to products.cgi."

I have this automated so whenever a new product is added, the URL for it is automatically created and stored. Zero maintenance converting the serp-y URL's to query strings. There are a number of ways to do this "conversion," whatever works for you in programming is what works for you.

More info here in the Apache Forum:
[webmasterworld.com...]

and mod_rewrite docs:
[httpd.apache.org...]