Forum Moderators: phranque
I'm trying to make links like this on
http://www.domain.com/section/action/url=http://www.google.com and I put the following line in the .htacces:
RewriteRule ^section/action/url=(.*)$ external.php?u=$2 [L,QSA] But, in PHP, I get $_GET['url'] = "http:/www.google.com" (note that address has a single slash)
If I try:
http://www.domain.com/external.php?url=http://www.google.com is working fine.
How can I avoid this behaviour? Or what I need to configure?
I need this to open a page with the url in a iframe.
I hope that you can help me with this issue. Thanks.
Note:
In the address that I supplied to you, the uri fragments "section" and "action" are only an examples
I only just want to know how to get the correct string value of a URL (or even another value with "//") passed via Query String like in the example.
[images.google.com.mx...]
A few things to try:
1) Try using the [NE] flag on your rule.
2) Encode the slashes as %2f%2f, *and* use the [NE] flag on your rule to prevent re-encoding (it would end up as %252f%252f otherwise)
3) Try publishing the URL (on the page generated by your script) in encoded form -- i.e. use "http:%2f%2fgoogle.com"
4) Just use a query string to pass that URL from the script, and don't bother trying to make it look like a static URL (it doesn't look like a normal URL anyway with "http" or "https" and a domain name on the end).
Jim
I'm managing the server and the server can be customize, so i'm not worried about the double slashes in the proyect. Also, I'm trying to make friendlies URLs with the .htaccess file.
I'll consider your suggestions, but ideally for my job is to try to customize the apache server o the .htaccess file to accept "//" in query string. I know that is possible (The google example), the question is "How to?".
Therefore, I strongly suggest revisiting the suggestions I made above.
Jim
At the end, I'm trying one of your suggestion: Encoding the url in the RFC 1738 standard format. (using %hex). Example
http://www.domain.com/section/action/http%3A%2F%2Fwww.google.com%2F I'm trying to capture the url in .htaccess:
RewriteRule ^/section/section/(.*)$ externo.php?u=$2 [QSA,L] But the server response to me with "Object not found!". I tried again by putting "?u=" (in .htaccess and in the url):
RewriteRule ^/section/section/?u=(.*)$ externo.php?u=$2 [QSA,L] But it's seems that just is ignoring.
The rule is written correctly or I missed something?
Also, if you want to pass encoded strings, you may need to use the [NE] flag on your rule.
It should not be necessary for your rule to examine the query string at this point. It may be needed later to refine the function, but not to test whether your hex-encoded URLs can pass through mod_rewrite and be un-encoded successfully by your script.
Try using the "Live HTTP Headers" add-on for Firefox/Mozilla browsers to examine the HTTP transactions between your browser and your server. This may help you to make some sense about what is going on.
Jim
@g1smd: You are right. It must be $1 instead of $2. I mistype in the example. I'm studying about ReWriteCond.
@jdMorgan: You are right too. I tried without the starting slashes, but the same problems. I'm studying about flags too. I'm using "httpFox" addon for FireFox, but I'm trying the add-on that you suggested. Both are very useful.