Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Need help redirecting domains but keeping extensions

Quote Reply
Need help redirecting domains but keeping extensions
Let me explain.

I have a short URL that I want to link to the regular URL and match the page linked.

For example, I'm trying to get:

shorturl.com/123.html
shorturl.com/<%ID%>.html

to (redirect, rewrite?) display the original URL like:

mywebsite/directoty/subdirectory/123.html
mywebsite/<%g%><%ID%>.html

I have tried the usual RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301,L] but it just results in /cgi-bin/links/page.cgi every time.
Quote Reply
Re: [MJB] Need help redirecting domains but keeping extensions In reply to
Hi,

Sorry, I'm not sure what you're trying to do? You want to create "short" URLs, which go to the full URL? Could you give a few more examples of what you're trying to do? Your example seems to be mixing both detailed pages, and categories :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Need help redirecting domains but keeping extensions In reply to
Yes, sorry, bad example that.

I have a short domain. I am using it for social media but I don't want it to resolve to the short domain when clicked. I only want it as a link to get to the full domain.

Is that any clearer?
Quote Reply
Re: [MJB] Need help redirecting domains but keeping extensions In reply to
Hi,

Right ok - so you basically want to let them send to foo.com/1234 , which would then lookup the correct URL for category 1234... and send them to the main site? Kinda like I do on my steampunk site:

http://steamp.co/s/G8NmD

Ya?

If so, what you need is a little script to pass it along to. For example:

Code:
RewriteRu[0-9]+0-9]+)$ /cgi-bin/gotocat.cgi?ID=$1 [R=301,L]

Then the script would take in the ID value, create a url using $DB->table("Category")->as_url( ID ) ... and then redirect them

I'm a bit busy with other work atm, but I'll see if I can knock up a simple script for you later today

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Need help redirecting domains but keeping extensions In reply to
Yes, that's what I'm trying to achieve.

I didn't realise it would involve creating a script though. I thought it might have just been a line that I needed to add to the .htaccess file.

Thanks for clearing that up.
Quote Reply
Re: [MJB] Need help redirecting domains but keeping extensions In reply to
Hi,

Ok, so this is totally untested Angelic

Call the script goshort.cgi, and put in the SHORT domain (not the main one).

Code:
#!/usr/local/bin/perl
use strict;
use lib '/path/to/admin';
use Links qw/$IN $DB $CFG $USER/;
use CGI::Carp qw(fatalsToBrowser);

local $SIG{__DIE__} = \&Links::fatal;

Links::init('/path/to/admin');

# steamp.co/cgi-bin/rand=mn3Gl

# do this for mod_perl compatbility...
handle();

sub handle {

if ($IN->param("ID") =~ /^\d+$/) {

my $rec = $DB->table("Category")->select( { ID => $IN->param("ID") })->fetchrow_hashref || {};

if ($rec->{Name}) {

my $url = "$CFG->{build_root_url}/" . $DB->table("Category")->as_url( $rec->{Full_Name} );
print "Location: $url\n\n";


} else {
print "Location: $CFG->{build_root_url}\n\n";
}
} else {
print "Location: $CFG->{build_root_url}\n\n";
}

}


Then also add this into the .htaccess for the SHORT domain:

Code:
RewriteRule ^([0-9]+)$ /cgi-bin/goshort.cgi?ID=$1 [R=301,L]

The, call the short URLs as:

http://shortdomain.com/123

...and that should the pass to the script, which will then lookup the correct URL to 301 to.

Hope that works / helps Cool

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Need help redirecting domains but keeping extensions In reply to
Thanks Andy