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
It isn't.
DirectoryIndex index.html index.htm index.php
order allow,deny
allow from all
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
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]
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&h=$6 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [L]
DirectoryIndex index.html index.htm index.php
order allow,deny
allow from all
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
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]
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&h=$6 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [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
You're going to drive yourself slowly insane doing it this way. I have to suggest again that you look back at the method I mentioned earlier using the 404 handler and a database.
-
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 Eric, but absolutely no way can I do it that way.
This way works brilliantly, specially with hyphens.
I just need to be able to run the pagenum part (second rule), and then I am sorted!
This way works brilliantly, specially with hyphens.
I just need to be able to run the pagenum part (second rule), and then I am sorted!
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 not? It's much cleaner and easier to maintain than 6+ lines of rewrite rules. Especially a year from now when you need to make changes to it and have to try to relearn what all those lines are doing all over again.
-
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
These are all the lines I need.
Having spent two days writing all this and updating a massive web site, and with 'pickles' help - sorry no.
Just need to know what I am doing wrong with that pagenum example.
Having spent two days writing all this and updating a massive web site, and with 'pickles' help - sorry no.
Just need to know what I am doing wrong with that pagenum example.
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
Can you not tag things on the end of a ShortUrl?
So how do you tag something on the end of a shorturl, and store it it a variable? I assumed it would take $sn as a variable and put "yes" into it.
But it doesn't.
Here is my URL for a shirt. It's posted to an external site and then comes back with the "&sn=yes" which the page should see as stating something has been sent, and disables the form from being used again./PRODUCT/BIG-RED-SHIRT/&sn=yes
So how do you tag something on the end of a shorturl, and store it it a variable? I assumed it would take $sn as a variable and put "yes" into it.
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.
Re: Short / Tiny URL - how do you do it, and how can it work
This is one of the problems with the rewrite technique. It is going to modify your URL's and in some cases drop data. I know I'm a broken record, but if you handle the short links with PHP code and a database you'll have easy 100% control. As a bonus you'll also see valid missing links show up, missing external links (which you can properly redirect), and monitor your short-URL traffic directly.simonmlewis wrote:Can you not tag things on the end of a ShortUrl?/PRODUCT/BIG-RED-SHIRT/&sn=yes
Perhaps you could modify your regex to pass on all the URL parameters to whatever page you are rewriting to by ignoring them, but I would have to spend a fair bit of time experimenting with it to fix your problem. I don't know off the top of my head.
-
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
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\xampp\phpMyAdmin\test1"
ServerName test1domain.local
<Directory "C:\xampp\phpMyAdmin\test1">
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\xampp\phpMyAdmin\test2"
ServerName test2domain.local
<Directory "C:\xampp\phpMyAdmin\test2">
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>It says "Server not found" so it's not a HTACCESS error.
What have I done wrong with this config file??
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
That's both a new, and an Apache config question, so it should be asked in the System > Installation & Configuration forum.
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
Don't worry it was simple: the HOSTS file wasn't updated. How about this problem tho:
RewriteEngine On
RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=sub [L]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=categ&c=$1&cname=$2&menu=sub&pagenum=$3 [L]
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
RewriteRule ^subcateg/page/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub&pagenum=$5 [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&h=$6 [L]
RewriteRule ^productsall/([0-9]+)/ /index.php?page=productsall&pagenum=$1/ [L]
RewriteRule ^sml/([^/]+) /index.php?page=a_login [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [L]
I need the "sml/" rule to show index.php?page=a_login.
Even tho other /fred rules will show 'page=fred'. So basically that rule should override the other rule.
How do I do that?
RewriteEngine On
RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=sub [L]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=categ&c=$1&cname=$2&menu=sub&pagenum=$3 [L]
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
RewriteRule ^subcateg/page/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub&pagenum=$5 [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&h=$6 [L]
RewriteRule ^productsall/([0-9]+)/ /index.php?page=productsall&pagenum=$1/ [L]
RewriteRule ^sml/([^/]+) /index.php?page=a_login [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [L]
I need the "sml/" rule to show index.php?page=a_login.
Even tho other /fred rules will show 'page=fred'. So basically that rule should override the other rule.
How do I do that?
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 am not very confused.
If a link goes to http://www.domain.co.uk/videos
It takes them to:
But /videos goes to that extended URL.
There are no rules in my HTACCESS that controls it. The problem is, when that page is up, and they click a link in the side menu that goes to /categ/55/fred..... it actually goes to /videos/categ/55 .....
Why would one page show a different url?
My HTACCESS file:
If a link goes to http://www.domain.co.uk/videos
It takes them to:
But if they go to /productsall, /contact, /faq .... etc, they all just show /productsall.... etc in the URL.videos/?page=videos&menu=home
But /videos goes to that extended URL.
There are no rules in my HTACCESS that controls it. The problem is, when that page is up, and they click a link in the side menu that goes to /categ/55/fred..... it actually goes to /videos/categ/55 .....
Why would one page show a different url?
My HTACCESS file:
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]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=sub [L]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=categ&c=$1&cname=$2&menu=sub&pagenum=$3 [L]
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
RewriteRule ^subcateg/page/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub&pagenum=$5 [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&h=$6 [L]
RewriteRule ^productsall/([0-9]+)/ /index.php?page=productsall&pagenum=$1/ [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [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
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
simonmlewis wrote: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.
Copypasta + thread necromancy = locked.munkitkat wrote: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.