URL rewriting help please!

 
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting
View previous topic :: View next topic  
Author Message
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Sat Jul 07, 2007 6:02 pm    Post subject: URL rewriting help please! Reply with quote

*edit:* I've got the url rewrting working, but now i need a bit more help! See my post at the bottom

I'm in the middle of a php project, and now I'm stuck because what I need to do next involves url rewriting!

I've got a couple of the basic ones, but I need to know if those ones are correct!

These are the only ones that is working for me!
Code:
/url/([a-zA-Z0-9]+) -> /url.php?show=$1 stop

Code:
/url -> /url.php continue


These are the ones I need help on
Code:
/tags/tag1/tag2/tag3 -> /tags.php?tag[]=tag1&tag[]=tag2&tag[]=tag3

Code:
/tags/tag1/tag2/tag3/url/goolglecom-> /url.php?show=googlecom


I also need
Code:
/tags -> /tags.php


The project is actually located in /projects/links/ but I can change any url's!

Thanks for any help!
_________________
Anthony R

Roganty
| Links-Links.co.uk


Last edited by roganty on Tue Aug 21, 2007 1:04 pm; edited 2 times in total
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Jul 09, 2007 2:30 pm    Post subject: Re: URL rewriting help please! Reply with quote

roganty,

Code:
/tags/tag1/tag2/tag3 -> /tags.php?tag[]=tag1&tag[]=tag2&tag[]=tag3


In regex lingo, it is:

Code:
^/tags/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ -> /tags.php?tag[]=$1&tag[]=$2&tag[]=$3


The next one is:

Code:
^/tags/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/url/([a-zA-Z0-9]+)$ -> /url.php?show=$4


The last one is the simplest:
Code:
^/tags$ -> /tags.php

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Tue Jul 10, 2007 10:27 am    Post subject: Re: URL rewriting help please! Reply with quote

Thanks aprelium, I will have a little play with them next time I have some free time!

Just a couple of quick questions, would I have to create a separate rule if I wanted:
Code:
/tags/tag1/tag2 -> /tags.php?tag[]=tag1&tag[]=tag2

-and-
Code:
/tags/tag1 -> /tags.php?tag[]=tag1


What would happen if I used relative urls?
And what do I put for "Next Action"?
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Wed Jul 11, 2007 12:17 am    Post subject: Re: URL rewriting help please! Reply with quote

roganty wrote:
Thanks aprelium, I will have a little play with them next time I have some free time!

Just a couple of quick questions, would I have to create a separate rule if I wanted:
Code:
/tags/tag1/tag2 -> /tags.php?tag[]=tag1&tag[]=tag2

-and-
Code:
/tags/tag1 -> /tags.php?tag[]=tag1


What would happen if I used relative urls?
And what do I put for "Next Action"?


Just a note: With your /tags.php?tag[]=tag1&tag[]=tag2 URL syntax, there might be problems in your PHP script if you use $_GET['tag[]'] to grab that variables from the query string.

To question 1, yes, you would have to make a separate rule. You might rather use
Code:
^/tags/([a-zA-Z0-9/)
and parse the actual tags within your PHP script using a for loop. Just one regex would cover many URLs like tag/tag/tag/tag/tag/tag/tag...

Relative URLs are interpreted by the browser and turned into absolute URLs, so that's not an issue for you. The incoming request is like this: GET /tags/tag1/tag2. You can see for yourself in IE with this program: ieHTTPheaders - download (132 KB).

The next action attribute is for even more advanced and complex URL rewrites. Just select none and everything should work just fine. You might read the documentation for an explanation, though.
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Wed Jul 11, 2007 1:03 am    Post subject: Re: URL rewriting help please! Reply with quote

pkSML
Thanks for answering my questions.
I think I have them set up correctly, it is at least working! Lol!

pkSML wrote:
To question 1, yes, you would have to make a separate rule. You might rather use
Code:
^/tags/([a-zA-Z0-9/)

and parse the actual tags within your PHP script using a for loop. Just one regex would cover many URLs like tag/tag/tag/tag/tag/tag/tag...

By doing it that way, it saves on rewriting rules, seeing as each level will need a "url" and "page", so thats three times as many rules!
Edit: Just thought, could use the "Next Action" to append additional tags to the end of the url. Is that even possible!?

pkSML wrote:
Just a note: With your /tags.php?tag[]=tag1&tag[]=tag2 URL syntax, there might be problems in your PHP script if you use $_GET['tag[]'] to grab that variables from the query string.

With regards to using tag[] in a url
print $_GET['tag'] outputs Array
print_r($_GET['tag']) outputs Array(0=>value)
So $tag = $_GET['tag'] can b used to get the list of tags
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Tue Aug 21, 2007 1:11 pm    Post subject: abyss to apache rewrite rules! Reply with quote

*edit:* Ive now been able to test the rewrite rules, and they do work. Thanks for your help

I now have the rewrite rules working, but now I need to convert them to the apache equivalent!

Here is the Abyss rewrite rules
Code:
url/([a-zA-Z0-9]+)/?$ -> /projects/links/url.php?show=$1 stop
^/projects/links/url/?$ -> /projects/links/url.php stop
^/projects/links/tags/?$ -> /projects/links/tags/all/ continue
^/projects/links/tags/([a-z0-9/]+)/page/([0-9]+) -> /projects/links/tags.php?tags=$1&page=$2 stop
^/projects/links/tags/([a-z0-9/]+) -> /projects/links/tags.php?tags=$1 stop


And this is what I have for Apache
Code:
RewriteEngine On
RewriteBase /links/
RewriteRule url/([a-zA-Z0-9]+)/?$ /links/url.php?show=$1 [NC,QSA,L]
RewriteRule ^url/?$ /links/url.php [NC,QSA,L]
RewriteRule ^tags/?$ /links/tags/all/ [NC,QSA,C]
RewriteRule ^tags/([a-z0-9/]+)/page/([0-9]+) /links/tags.php?tags=$1&page=$2 [NC,QSA,L]
RewriteRule ^tags/([a-z0-9/]+) /links/tags.php?tags=$1 [NC,QSA,L]


Do they look correct?

Thanks for all of your help
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> URL Rewriting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group