Page 5 of 6
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 3:11 am
by simonmlewis
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.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 6:10 am
by simonmlewis
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.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 7:56 am
by simonmlewis
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]
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 9:50 am
by pickle
.* works for a match to "anything". If you do that, you'll want to follow it with a ? so the subpattern isn't greedy.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 9:52 am
by simonmlewis
Sorry, where do I put a ?, and what do you mean "so the subpattern isn't greedy"?
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 10:01 am
by pickle
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"
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 10:06 am
by simonmlewis
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?
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 10:12 am
by pickle
It all depends on what you want to pull out of the URL - my example was just generic.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Tue Jan 10, 2012 10:14 am
by simonmlewis
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.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Wed Jan 11, 2012 4:51 am
by simonmlewis
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.
Code: Select all
RewriteRule ([^\-]+)\-([^\-]+)\-([^\.]+)\.htm$ /$1.php?$2=$3 [L,QSA]
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.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Wed Jan 11, 2012 5:44 am
by simonmlewis
I might add this to a new thread, as it is no longer really a TinyURL - but a HTM conversion.
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]
These don't work either.
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.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Wed Jan 11, 2012 7:56 am
by simonmlewis
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]
This second rule isn't working.
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?
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Wed Jan 11, 2012 11:11 am
by pickle
Remember the last slash is a character that must be matched (or not if it's not there).
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Wed Jan 11, 2012 11:21 am
by simonmlewis
Even with ..... /2/
it won't work. No errors, but doesn't recognise "pagenum" is now 2.
Re: Short / Tiny URL - how do you do it, and how can it work
Posted: Wed Jan 11, 2012 11:28 am
by pickle
Why is this in there: ([^/\.]+) ?