views:

49

answers:

1

Hi Folks!

I'm trying to pass an URL as a parameter in mod-rewrite. I guess there is a problem in my Regex. This my .htaccess:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule **^go/((http:\/\/)+[A-Za-z0-9\-]+[\.A-Za-z])/?$** feedmini.php?url=$1 [L]
</IfModule>

the URL I want to pass looks like http://www.aaaa.com/aaa/?q=v but when ever I try to reach it on go/http://www.aaaa.com/aaa/?q=v I get an 404 error page. I've also tried with **^go/([A-Za-z0-9\-\/:]+[\.A-Za-z]+)/?$** but then the URL i pass gets like this: http:/www.aaaa.com/aaa/ (observe the singel '/' after 'http:');

Any Ideas?

Thanks in advance /Ale

+1  A: 

Well your first problem (in your first code block) is that your Regex pattern will not match a URL since it will only match a string that begins with http:// then contains nothing but alphanum or dashes, which ends with a single fullstop or letter. Perhaps this is simply a typo and there should be a quantifier in there, but even so it would fail to match a very large percentage or URLs.

This may seem a little strange, but try this...

RewriteRule ^go/http:/(.*)/?$ feedmini.php?url=http://$1 [R=302,L]
Cags
Note that the `/?` at the end will never match, because the `.*` will grab the trailing slash greedily if it's there (which is fine). Also, +1, since this is the right answer. Any number of multiple slashes will be condensed into a single slash before being passed to the `RewriteRule` test pattern.
Tim Stone
Good point Tim, I guess I'm just used to writing /? at the end of my patterns :)
Cags
Hi, thanks for the help! Its working perfect now. I think I should learn more about Regex ;)
Alecoleti