Jump to content

[HOW?]External(outgoing) URLs redirection using .htaccess


Recommended Posts

Hi,

I have a question: How can I redirect external(outgoing) URLs from my site using .htaccess, so searchengines will consider them as local.

Here's an example:

http://mysite.com/redir?http://externalurl.com

I have a script(plugin) that can convert common urls(like http://externalurl.com) to the ones above on html-output.

 

P.S. I know about the similar solution using a php-file, but I just want to know how to do the same using .htaccess

 

Thanks in advance.

Thanks for reply. But unfortunately it's not working for me as it have to - for when I click on the url it's just redirecting me back to the frontpage(I tested it on gnix host).

P.S. I'm using Joomla, so there also will be the following code in .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php

By the way, I tested the proposed solution with and without it, but the result was still the same.

Thanks, it really works fine without http:// and with http:// the final link form transforms into something like http://http/externalurl.com/...

Though it's not so big deal, 'cause there'll no problem to remove http:// on output(using php) or is it possible to remove it using .htaccess?

 

P.S. Besides. is there any way to insert = symbol between redir and exterlal URL(like: http://mysite.com/redir=http://externalurl.com) or something like that, so outgoing link will be marked out from site link.

Well the http:// on the rule is required or Apache thinks it's a local URL.

 

 

The http:// could be made optional in the matching though....

 

Something like:

 

RewriteRule ^redir?url=(http://)?(.*) http://$1/ [L,R=301]

 

 

That would make it in the format redir?url=http://google.com or redir?url=google.com.

 

 

Untested so it might not work ;p.

RewriteRule ^redir=(.*) http://$1/ [L,R=301]

 

 

To be honest, I forgot about this thread.  I need to look at a regular expression reference and remember how to make a group optional.

 

 

I thought

 

RewriteRule ^redir/(?:http://)?(.*) http://$1/ [L,R=301]

 

Would work, but it doesn't x.x.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.