views:

17

answers:

1

Hi all,

I recently discovered mod rewrite and I was wondering if it's possible to rewrite a variable which contains an outbound url.

So far it is not working at all. I assume it is caused because of the special characters in the variable and I have no clue how I can solve this.

My .htaccess code so far:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^url/(\w+)/?$ link.php?url=$1 [L]

I would like to rewrite:

http://www.example-site.com/url/http://www.affiliate-site.com/dir/index.php?page=home

To:

http://www.example-site.com/link.php?url=http://www.affiliate-site.com/dir/index.php?page=home

Any help would be much appreciated.

Thanks in advance.

A: 

\w is only a-z, A-Z and 0-9

This should do the trick:

RewriteRule ^url/(.+)/?$ /link.php?url=$1 [L]

This cheat sheet can help:
http://regexlib.com/CheatSheet.aspx

Kerry
Hi Kerry, Thanks, that worked indeed.However, I ran into another issue, when I enter "http://www.affiliate-site.com" and I echo the GET variable in my php file it comes out as "http:/www.affiliate-site.com". Notice that the double slash outputs as a single slash. And when the url contains a query "?", it cuts off the query in the url. So "http://www.affiliate-site.com/dir/index.php?page=home" turns into "http:/www.affiliate-site.com/dir/index.php".Any idea why this happens? And how I could solve it?Best Regards
Invalid User
As for removing the double //, are you doing `stripslashes()` on the URL? As for the query string, yes, it thinks anything after the ? is a query string. To get around this, I would read in and replace the current URL from the `$_SERVER['REQUEST_URI']`. This can get you JUST the url you are looking for, then use http://www.php.net/manual/en/function.parse-str.php to get the variables you need.
Kerry