Short / Tiny URL - how do you do it, and how can it work?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
I've been looking at that tutorial to see if there is an option that says "anything" added in that section, tho maybe that is dangerous.
So it could be "aZ09- ".
I cannot get the - to be accepted with the \s. I think once I get that working, I can work out the rest, as I have got the product pages working, and feeding thru the catids, subid, and names. I'll be able to work thru the search, tho might just leave the search as it is.
And be very useful to use HTACCESS to prevent images from being taken too.
So it could be "aZ09- ".
I cannot get the - to be accepted with the \s. I think once I get that working, I can work out the rest, as I have got the product pages working, and feeding thru the catids, subid, and names. I'll be able to work thru the search, tho might just leave the search as it is.
And be very useful to use HTACCESS to prevent images from being taken too.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
RewriteRule ^subcateg/([0-9]+)/([^/\.]+)/([0-9]+)/([^/\.]+)/ /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
This works for just about anything, including FRED-SMITH as a sub category name, but not if there is a full stop in there:
FRED.SMITH
And we do have those. So how do I let it accept just about anything?? (or is that dangerous?)
Needs to take upper and lower case, any numbers, underscore, fullstops and hyphens.
This works for just about anything, including FRED-SMITH as a sub category name, but not if there is a full stop in there:
FRED.SMITH
And we do have those. So how do I let it accept just about anything?? (or is that dangerous?)
Needs to take upper and lower case, any numbers, underscore, fullstops and hyphens.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
Bingo:
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/ /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/ /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&menu=sub&product=$5&head=$6 [L]
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/ /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/ /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&menu=sub&product=$5&head=$6 [L]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Short / Tiny URL - how do you do it, and how can it work
.* works for a match to "anything". If you do that, you'll want to follow it with a ? so the subpattern isn't greedy.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
Sorry, where do I put a ?, and what do you mean "so the subpattern isn't greedy"?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Short / Tiny URL - how do you do it, and how can it work
Take this pattern: :plan/(.*)/:
And this URL: /plan/234/abcd/blah/
The parenthesis will match "234/abcd/blah/" because (.*) is greedy - it will match as many characters as possible. If the pattern changes to
:plan/(.*?)/:, the ".*" is no longer greedy, and will only match characters until the character following the subpattern (in this case a /) is found. With the ? in there, the parenthesis will match "234"
And this URL: /plan/234/abcd/blah/
The parenthesis will match "234/abcd/blah/" because (.*) is greedy - it will match as many characters as possible. If the pattern changes to
:plan/(.*?)/:, the ".*" is no longer greedy, and will only match characters until the character following the subpattern (in this case a /) is found. With the ? in there, the parenthesis will match "234"
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
Sorry to be dumb again, but I still don't get it.
if your URL is a correct one, why is it being greedy - don't you need that full URL?
if your URL is a correct one, why is it being greedy - don't you need that full URL?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Short / Tiny URL - how do you do it, and how can it work
It all depends on what you want to pull out of the URL - my example was just generic.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
You said mine is being greedy. It's working, so I don't know what you mean by greedy, sorry. And your example doesn't really explain it to me.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
We've found out that there are issues with IE converting spaces into "%20".
So we are now looking at using it and converting to look like HTML instead:
Such as: index.php?page=product&id=4&title=T SHIRT&c=34&cname=Large
Into...
4-T-SHIRT-34-LARGE.html.
This looks like the sort of thing that does it, ,but going back to the previous pages of this thread, you use different rules for different links:
categ/....
subcateg/....
So how do you do this for different lengths of URLS?
As some will just be:
/34-T-SHIRT.html
and some will be:
/34-T-SHIRT-44-black-786-BLACK.html.
Is there just ONE long RULE above that you use, or do you set different lengths for each different one you have?
So you have the categ, subcateg and product rules, knowing how long each will be?
Also, how does it add the - into the product name, if the DB title is actually just "T SHIRT"?
Thank you again.
So we are now looking at using it and converting to look like HTML instead:
Such as: index.php?page=product&id=4&title=T SHIRT&c=34&cname=Large
Into...
4-T-SHIRT-34-LARGE.html.
Code: Select all
RewriteRule ([^\-]+)\-([^\-]+)\-([^\.]+)\.htm$ /$1.php?$2=$3 [L,QSA]categ/....
subcateg/....
So how do you do this for different lengths of URLS?
As some will just be:
/34-T-SHIRT.html
and some will be:
/34-T-SHIRT-44-black-786-BLACK.html.
Is there just ONE long RULE above that you use, or do you set different lengths for each different one you have?
So you have the categ, subcateg and product rules, knowing how long each will be?
Also, how does it add the - into the product name, if the DB title is actually just "T SHIRT"?
Thank you again.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
I might add this to a new thread, as it is no longer really a TinyURL - but a HTM conversion.
I thought the top one would take the page name, c number, cname word and put it all in, and add any hyphens where there are spaces, but it doesn't.
These don't work either.RewriteCond %{REQUEST_URI} ([^\-]+)\-([^\-]+)\-([^\-]+)\.htm$
RewriteRule ([^\-]+)\-([^\-]+)\-([^\-]+)\.htm /index.php?page=$1&c=$2&cname=$3 [L,QSA]
RewriteCond %{REQUEST_URI} (.+)\.htm$
RewriteRule ^([a-z0-9_]+)\.html$ /index.php?page=$1 [NC,L]
I thought the top one would take the page name, c number, cname word and put it all in, and add any hyphens where there are spaces, but it doesn't.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
Code: Select all
RewriteRule ^categ/([0-9]+)/([^/\.]+)/ /index.php?page=categ&c=$1&cname=$2&menu=sub [L]
RewriteRule ^categ/([0-9]+)/([^/\.]+)/([0-9]+)/ /index.php?page=categ&c=$1&cname=$2&menu=sub&pagenum=$3 [L]I need to pass through a page number for pagination. But this isn't passing the page number over.
This is the URL: /categ/$catid/$cname/$page
The number is going thru:
http://domain.local/categ/44/Accessories/2
So why isn't it working? IS my htaccess setwrong?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Short / Tiny URL - how do you do it, and how can it work
Remember the last slash is a character that must be matched (or not if it's not there).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Short / Tiny URL - how do you do it, and how can it work
Even with ..... /2/
it won't work. No errors, but doesn't recognise "pagenum" is now 2.
it won't work. No errors, but doesn't recognise "pagenum" is now 2.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Short / Tiny URL - how do you do it, and how can it work
Why is this in there: ([^/\.]+) ?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.