1

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

2
  • Do you mean that your URLs are like http://example.com/go/http://stackoverflow.com/? Commented Aug 14, 2010 at 9:40
  • Hi Tim! Yeah, that's exactly what I want to accomplish, but I havent got any positive results yet. Commented Aug 14, 2010 at 12:19

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

3 Comments

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.
Good point Tim, I guess I'm just used to writing /? at the end of my patterns :)
Hi, thanks for the help! Its working perfect now. I think I should learn more about Regex ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.