Trying to shorten a long url

Discuss practical ways rearrange URLs using mod_rewrite.

Trying to shorten a long url

Postby JenSEO » Tue Jun 24, 2008 5:31 am

Hi,

I'm very new to mod_rewrite and struggling to figure this all out. I'm not sure I'm understanding how it all works and what needs to be done.

Right now I'm trying to see if it's possible to shorten a url that looks like thei following:

Code: Select all
http://somewebsitestore.com/store/site/department.cfm/id/36066205-ABB9-2520-78831B4EA3D4D8D7/sectid/CDB2AA58-E02F-0FD9-10F0F689297BEECA


Can that be shortened down any? Or are the rewrites meant for just the php directory/product variables like I've seen in the examples?

Thanks
JenSEO
 
Posts: 5
Joined: Mon Jun 09, 2008 11:52 am

Postby richardk » Tue Jun 24, 2008 2:27 pm

You can rewrite anything, within reason. You could have just /36066205-ABB9-2520-78831B4EA3D4D8D7/CDB2AA58-E02F-0FD9-10F0F689297BEECA/, if you want, but it's better to leave something in there that is unique and doesn't change to help stop conflicts with other rules.

For /store/36066205-ABB9-2520-78831B4EA3D4D8D7/CDB2AA58-E02F-0FD9-10F0F689297BEECA/, in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^store/([-a-z0-9]+)/([-a-z0-9]+)/?$ /store/site/department.cfm/id/$1/sectid/$2 [QSA,L]

^store/([-a-z0-9]+)/([-a-z0-9]+)/?$ is matched against the part of the URL after the current directory (in this case /) and up to the ? (if there is one).
([-a-z0-9]+) matches letters, numbers and dashes and puts them in a backreference (variable), $1 and $2. They are used to build the original URL.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby JenSEO » Wed Jun 25, 2008 4:51 am

Thank you for the reply.

So realistically it couldn't be much shorter than it already is without causing conflicts with other pages that have similar strings in the url? As in I'd end up with duplicated urls as there wouldn't be enough variation?

Also - I asked this once before and mistakenly put it in the wrong section. I did get an answer but it wasn't clear. Does each url need it's own rule or would there be one rule that would be applied to all pages?
JenSEO
 
Posts: 5
Joined: Mon Jun 09, 2008 11:52 am

Postby richardk » Thu Jun 26, 2008 1:10 pm

So realistically it couldn't be much shorter than it already is without causing conflicts with other pages that have similar strings in the url? As in I'd end up with duplicated urls as there wouldn't be enough variation?

It all depends one what the other URLs are. What exactly would you like the URL to be? What other URLs do you have (that might conflict with it)?

What duplication are you referring to? I was thinking conflict between rules, like in this thread.

Also - I asked this once before and mistakenly put it in the wrong section. I did get an answer but it wasn't clear. Does each url need it's own rule or would there be one rule that would be applied to all pages?

You did, here. There isn't enough information about what you want to do to give a clear, single solution. You can match every request to your site with mod_rewrite with one rule. It all depends one what you want to do once mod_rewrite has matched the requests.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby JenSEO » Thu Jul 03, 2008 7:24 am

Well using a different site from my first example I've got real estate client I'm trying to do mod_rewrites for and I if there's searches for different houses would i be able to have one rule for all possible searches based off what the results end up being? Or do I need a different rule for each search based on what is being searched - new homes vs. condos vs. apartments and so on and so forth.
JenSEO
 
Posts: 5
Joined: Mon Jun 09, 2008 11:52 am

Postby richardk » Fri Jul 04, 2008 2:24 pm

If the parameters (their names) are the same, yes. For example you can have one rule for
/pages/apples/1/ --> /file.php?page=apples&page=1 and
/pages/pears/5/ --> /file.php?page=pear&page=5 and
/articles/chairs/3/ --> /file.php?article=chairs&page=3

but not for
/pages/apples/1/ --> /file.php?page=apples&page=1 and
/forum/topic1/ --> /forum.php?action=topic&id=1

because they have different parameters.

It would be a lot easier if you gave examples of the URLs.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby JenSEO » Thu Jul 10, 2008 10:23 am

Okay, here is an example url from the real estate client's mls search listings:

Code: Select all
http://example.com/adv_listing_index.php?rg=Any&nbr=&z=Any&sch=&mlid=&pmn=&pmx=&bmn=&bmx=&btmn=&btmx=&smn=&smx=&ymn=&ymx=&lmn=&lmx=&pt=Any&bd=Any&pl=Any&gc=Any&g=Any&srt=listprice&ord=asc&em=&subFrm.x=32&subFrm.y=6&adv=1&new_con=&hi_rise=&golf=&mls_hi_rise=


What would be the easiest way to work with it?
JenSEO
 
Posts: 5
Joined: Mon Jun 09, 2008 11:52 am

Postby richardk » Sun Jul 13, 2008 11:13 am

Nothing is going to make that URL friendly, it will always be a list of nonsense. And you have to decide how you would like it.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 25 guests

cron