|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > (mod) rewriting urls |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|