Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 9th, 2001, 09:47 AM
wifpwcs wifpwcs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 28 wifpwcs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 21 sec
Reputation Power: 0
Question (mod) rewriting urls

First, I want to apolgize for probably bringing up a repeated subject. I have already searched through the forum and read all suggested resources but I am still a bit confused. The following is for browsing a catalog.

Problem:
Rewriting PHP dynamic links (without php scripting)
example:
www.name.com/browse.php?category=1&offset=9
www.name.com/browse/category/1/offset/9

(Potential) Additinal Problem:
My urls are not always the same (unless I pass blank parameters(?). My script *can* accept more parameters than are usually passed (if a parameter isn't passed, it goes to default. -ie. $page_offset=9. So my url code could presently be written as:

http://www.name.com/browse.php?cate...fset=12&color=2

- or as -

www.name.com/browse.php?category=1&start_item=1

Server:
- Hosting company (shared server)
- OS: linux (ver?)
- Apache (1.3.12 Cobalt w/ mod_rewrite)
- can only change / create .htaccess files

I'm not just asking for a solution -- I'm eager to learn this by example. Thanks

Reply With Quote
  #2  
Old August 9th, 2001, 01:35 PM
piet piet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bend, OR
Posts: 96 piet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
wifpwcs:

I have been learning the ropes about mod_rewrite and perhaps I can spare freebsd some time. However, he is the expert and may need to step in at some point. I will share what I know. Which is mostly from freebsd (Thanks!) anyway.

Before I proceed you should really check out the following posts as they have helped me.

1. http://forums.devshed.com/showthrea...8661&forumid=15
2. http://forums.devshed.com/showthrea...8938&forumid=15
3. http://forums.devshed.com/showthrea...9203&forumid=15
4. http://httpd.apache.org/docs/mod/mod_rewrite.html


OK. So it seems to me you want your URL's to be search engine friendly and they should be in the form...

http://mydomain.com/category/group/product/etc...

Correct? Where the "category", "group", "product" will be the basis for a query string. At least that is how I use it, you may use it differently. I can't tell from your post if you also want to have URL's in the form of...

http://www.name.com/browse.php?cate...fset=12&color=2

I am not sure but I would think you would need a lot of URL rewriting to do if you want both.

However, if you want your URL's to look like the first way. Try this...

(Put this in your .htaccess or better your httpd.conf file)

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php.*
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^([A-Za-z0-9]+)/?$ index.php?request=$1 [T=application/x-httpd-php,L]
RewriteRule ^(.+) index.php?request=$1 [T=application/x-httpd-php,L]

This is just a mutation of what freebsd has posted. This will let you take out your URL as long as you want. For example...

http://mydomain.com/var1/var2/var3/var4/var5/etc..../

In you index.php script (or your case it looks like you are using browse.php) you can check for $REQUEST_URI. Parse the URI like so...

$url_array = explode ("/", $REQUEST_URI);

$var1 = $url_array [1];
$var2 = $url_array [2];
$var3 = $url_array [3];
$var4 = $url_array [4];
$var5 = $url_array [5];

I think you can take it from there. If you want your URL's the other way also then I am afraid freebsd (the mod_rewrite master) needs to step in.

Piet
__________________

- Please help us build our Hewlett Packard community
- Check us out, or tell someone who might find us useful

Last edited by piet : April 7th, 2003 at 03:37 PM.

Reply With Quote
  #3  
Old August 9th, 2001, 02:14 PM
wifpwcs wifpwcs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 28 wifpwcs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 21 sec
Reputation Power: 0
Thanks!

Piet,

That's exactly what I was looking for. Thanks for the response. I will try it once the approaching thunder storm passes.

One more question came to mind. I recall reading, and you hinted at it, that mod rules are best established in the httpd.conf.

I'm using a hosting company so the httpd.conf is off limits (only have access to .htaccess files). Is it still more efficent to use mod_rewrite, or should I try a scripting approach (http://www.zend.com/zend/spotlight/searchengine.php)?

I read that mod_rewrite in an .htaccess file needs to, more or less, send two request to the server because the url has already been parsed by the time it reads the directory specific .htaccess files.

What's your opinion?

Thanks again

Reply With Quote
  #4  
Old August 9th, 2001, 03:04 PM
piet piet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bend, OR
Posts: 96 piet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
wifpwcs:

It think it is a personal preference. I personally use the approach I laid out for you...it just looks a bit cleaner. It is true that if you put it in the httpd.conf file it does speed up the whole process a bit. But really, how many people have access to their httpd.conf file if their ISP is doing the hosting. You should be fine doing the mod_rewrite in the .htaccess file. Also, there are other ways to do this. You should read the phpbuilder article (and read the posted questions) ...

1. http://www.phpbuilder.com/columns/tim20000526.php3

There you will find another way. You can also check out my last posting on this forum....

2. http://forums.devshed.com/showthrea...9010&forumid=15

I just hope you don't run into the same stumbling block I did with the inability of not being able to detect your cookies or sessions. If all goes well for you then you need to tell me what hosting company you use. I have talked to many people that say all the methods should work just fine but for some reason the hosting company that I use (http://www.jtlnet.com) just doesn't seem to make it happen. Must be something in the way they set up their httpd.conf file. Not really sure though.

I have tried the method I posted on my development box using Win2K, Apache, PHP, MySQL and it is doing great.

Hope this all helps!

Piet

Last edited by piet : April 7th, 2003 at 03:37 PM.

Reply With Quote
  #5  
Old August 9th, 2001, 03:16 PM
wifpwcs wifpwcs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 28 wifpwcs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 21 sec
Reputation Power: 0
Thanks again

Piet,

Once again, I appreciate your response.
The hosting company I use is WebIntellects (www.webintellects.com). For 20 dollars a month, I get telnet access, 200 megs disk space, unlimited bandwidth -- (yep, even for commercial... they have different plans for ecomerce, though. I haven't discovered if you need to upgrade to the ecomerce plan if you make your own tools: shopping cart, etc.), 10 megs MySql, and the speed is pretty nice -- tops the charts on all bandwidth testing sites I've gone to.

I mention this in hopes that they might get more business and keep their prices low. Hopefully, more customers won't make them greedy- my last hosting company had that problem. :-(

Thanks again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > (mod) rewriting urls


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT