Forum Moderators: phranque

Message Too Old, No Replies

Redirect with request param

Redirect with request param

         

vince786

11:53 pm on Feb 8, 2011 (gmt 0)

10+ Year Member



I have a redirect which must include the request param as is:

[myhost:8080...]

to

[mynewhost:10080...]

Would appreciate help.

Thanks,

Vince

g1smd

12:35 am on Feb 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What code have you tried so far?

It's likely going to need two or three lines of code, one or two RewriteCond lines and one RewriteRule line with the
[R=301,L]
flags.

Do you also want to redirect if the port number is missing in the initial request?

Do you also want to redirect if the user includes parameters, but OMITS the index.php part in the initial request?

Both of those are perfectly valid requests and you must plan to either redirect them, or reject them.

vince786

9:53 pm on Feb 14, 2011 (gmt 0)

10+ Year Member



Hi g1smd,

Many thanks for the response.
What I want to achieve is:

htp://example.com:8080/shop/index.php?name=abc
should get redirected to:
htp://newexample.com:10080/shop/index.php?name=abc

If the port number is missing or index.php is missing then reject.

I have tried several things basically boiling down to the following:

RewriteCond %{SERVER_PORT} ^8080$
RewriteCond %{QUERY_STRING} ^name=abc$
RewriteRule ^.*index\.php$ htp://newexample.com:10080/shop/index.php?name=abc [R=301,L]

So if a user enters htp://example.com:8080/shop/index.php?name=abc
then the Rewrite rule would check for existence of index.php and would redirect to the new location. Apache is not happy and not doing the redirect. Shall appreciate any pointers.

Thanks,

vince

jdMorgan

10:22 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are both "ports" hosted in the same filespace, and therefore affected by this same code?

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com\.?:8080$
RewriteCond %{QUERY_STRING} ^name=abc$
RewriteRule index\.php$ htp://newexample.com:10080/shop/index.php [R=301,L]

This all boils down to whether this server is defined as listening only to port 8080, or if you are simply tacking that port number onto your hostname. Both valid approaches, but handled differently ( %{SERVER_PORT} versus %{HTTP_HOST}, that is).

The query string will be "carried through" this rule by default. So there is no need to specify it in the substitution URL.

Jim

vince786

6:38 pm on Feb 18, 2011 (gmt 0)

10+ Year Member



A Big Thank You! to you Jim.
The rule now works.
Re your question of the 2 ports being hosted on the same file space, my answer is probably no (I will look into to confirm 100%). The port 10080 is advertised to the public entering into the system whereas underneath the post is 8080. Without the rule a user using port 8080 and the uri would be rejected by the authentication system.

Vince