Page 4 of 6

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 2:03 pm
by pickle
Ya, but inside the [], as those specify a range of characters that should be considered a match. And really, all you need is just a space, not necessarily \s

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 2:09 pm
by simonmlewis

Code: Select all

DirectoryIndex index.html index.htm index.php
order allow,deny

allow from all 

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^categ/([0-9]+)/([a-Z0-9][ ]+)/ /index.php?page=categ&c=$1&cname=$2 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^$ index.php?page=home&menu=home [L]
This causes a Server Error on any page, even index.php?page=home.
Error 500. With or without the space.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 2:17 pm
by pickle
put the space inside the [] you already have: [a-Z0-9 ].

500 errors are a pain in the butt to figure out. Best to use that regex tester I pasted a few pages back to test your expression independently.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 2:19 pm
by simonmlewis
It's definintely only this:
RewriteRule ^categ/([0-9]+)/([a-Z0-9 ]+)/ /index.php?page=categ&c=$1&cname=$2 [L]

That is causing that error - as completely removed, it works fine in the basic index.php?page=home.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:01 pm
by simonmlewis
RewriteRule ^categ/([0-9]+)/([a-z0-9]+)/ /index.php?page=categ&c=$1&cname=$2 [L]

It likes this, but it doesn't like
RewriteRule ^categ/([0-9]+)/([a-Z0-9]+)/ /index.php?page=categ&c=$1&cname=$2 [L]
(capital Z)
RewriteRule ^categ/([0-9]+)/([a-z0-9 ]+)/ /index.php?page=categ&c=$1&cname=$2 [L]
Nor this, with the space in it.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:04 pm
by pickle
Hmmm, maybe you need to do [a-zA-Z0-9].

Not sure how to put the space in, if what I suggested is causing an error.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:08 pm
by simonmlewis
Yes that works, by which I mean it doesn't cause an error - BUT,
http://test.local/categ/49/Specials

Code: Select all

DirectoryIndex index.html index.htm index.php
order allow,deny

allow from all 

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^categ/([0-9]+)/([a-zA-Z0-9]+)/ /index.php?page=categ&c=$1&cname=$2 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^$ index.php?page=home&menu=home [L]
Produces this:
Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.
Error 404

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:15 pm
by pickle
Since there's no trailing slash, it's not matching your "categ" rule - must be one of the others.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:18 pm
by simonmlewis
Sorry, you mean it must be one of the other's causing what?
The error I had before is now gone. It was as you suggested.
But this 'categ' rule is not working, and is causing this problem.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:29 pm
by pickle
The URL "http://test.local/categ/49/Specials" would not match your first rule, as the first rule requires the URL to have a trailing slash. Therefore, the error you're getting must be caused by one of the other two rules.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:33 pm
by simonmlewis
It's the missing slash that was causing it. Didn't realise how important it was. It works with that.
So next is for me to see if I can figure out how to add the subid and subname....

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 3:55 pm
by simonmlewis
Fantastic, I've sussed it, and the Sub Category, and got it working dynamically from the side menus.

DirectoryIndex index.html index.htm index.php
order allow,deny

allow from all

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^categ/([0-9]+)/([a-zA-Z0-9\s]+)/ /index.php?page=categ&c=$1&cname=$2&menu=sub [L]
RewriteRule ^subcateg/([0-9]+)/([a-zA-Z0-9\s]+)/([0-9]+)/([a-zA-Z0-9\s]+)/ /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^$ index.php?page=home&menu=home [L]

Next job is to link the Product pages, and then put them on the Category pages themselves.
So I undertand the a-z, A-Z and 0-9, and I see what the / slashes are for, as they are part of the URL, but still not clear, even with that tutorial what the + sign means.
Can you elaborate in lamens terms please?

The \s works, as I have had words with spaces and it works. So cleaning it has to be \s rather than just a space put in there.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 4:04 pm
by pickle
The + means "match the preceeding character/range one or more times". Similarly, * means 0 or more times.

So if you have an expression like: abc8+, it would match the strings abc8 and abc888888888, but not abc. If you had abc8*, it would match abc.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 4:06 pm
by simonmlewis
. (dot) ANY single character at all

How do I put this in, as I have some product names with titles like: T-SHIRT
([a-zA-Z0-9\s.]+)
This doesn't work.

Re: Short / Tiny URL - how do you do it, and how can it work

Posted: Mon Jan 09, 2012 4:08 pm
by simonmlewis
Thank you for the + example. I'm sure there are times when that would come into play, not sure when tho.
I'm trying to work out this hyphen in the word. I might also add this to the category part too, as someone may just put in hyphens in there, and that would kill it!