xendex Posted March 19, 2009 Share Posted March 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/ Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 RewriteEngine On RewriteRule ^redir?(.*) $1 [L] Should do it. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-788856 Share on other sites More sharing options...
xendex Posted March 20, 2009 Author Share Posted March 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-789561 Share on other sites More sharing options...
corbin Posted March 21, 2009 Share Posted March 21, 2009 Hrmmm.... It's redirecting you to the front page? What do you mean? Edit: Hrmmm.... Just tried it my self, and I see what you mean. Messing with it now. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-790094 Share on other sites More sharing options...
corbin Posted March 21, 2009 Share Posted March 21, 2009 Well, realized earlier that ? was making the r in redir optional. RewriteEngine On RewriteRule ^redir/(.*) http://$1/ [L,R=301] Works without http://.... Trying to figure out something not to allow or not allow http://. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-790102 Share on other sites More sharing options...
xendex Posted March 21, 2009 Author Share Posted March 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-790431 Share on other sites More sharing options...
corbin Posted March 23, 2009 Share Posted March 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-791524 Share on other sites More sharing options...
xendex Posted March 23, 2009 Author Share Posted March 23, 2009 Just redirecting back to the frontpage... Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-791563 Share on other sites More sharing options...
corbin Posted March 23, 2009 Share Posted March 23, 2009 Hrmmm........ I must be making this harder than it is or something because this shouldn't be hard at all x.x. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-791829 Share on other sites More sharing options...
xendex Posted March 25, 2009 Author Share Posted March 25, 2009 So is there any way at least to put = between redir and external url? Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-793493 Share on other sites More sharing options...
corbin Posted March 25, 2009 Share Posted March 25, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-793925 Share on other sites More sharing options...
xendex Posted March 27, 2009 Author Share Posted March 27, 2009 RewriteRule ^redir=(.*) http://$1/ [L,R=301] Hm, this one really works perfectly if not using http:// Quote Link to comment https://forums.phpfreaks.com/topic/150159-howexternaloutgoing-urls-redirection-using-htaccess/#findComment-795393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.