简体   繁体   中英

Passing and URL as parameter in mod-rewrite

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM