url as parameter

Discuss practical ways rearrange URLs using mod_rewrite.

url as parameter

Postby a.nonymous » Tue Jul 22, 2008 12:59 pm

Hi,

I have the following problem. My script requires URLs via a parameter. E.g. http://mydomain.tld/submit.php?url=http://the-target.com/path/url.php?param1=value1&param2=value2

This example works fine. But now I want to have a URL like this: http://mydomain.tld/submit/http://...

and "submit/..." should be redirected to "submit.php?url=...". I already tried the following rule:
Code: Select all
RewriteRule ^submit/(.+)$ submit.php?url=$1 [L]


But this seems not to work. My script only gets the domain and path of the URL in the parameter (in this example: http://the-target.com/path/url.php)

Does anyone have an idea to solve this problem?
a.nonymous
 
Posts: 1
Joined: Tue Jul 22, 2008 12:48 pm

Postby richardk » Wed Jul 23, 2008 7:31 am

The query string of the first URL is not passed automatically. You can pass them on with the QSA (Query String Append) flag, however they willl not be part of the url parameter.
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

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

This will produce
Code: Select all
Array
(
    [url] => http:/the-target.com/path/url.php
    [param1] => value1
    [param2] => value2
)


If they need to be part of the url parameter you will need to get it from the REQUEST_URI variable in your PHP script.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 96 guests

cron