Reputation: 677
I have a domainA.com which I would like to redirect it to:
domainB.com/public.php?service=shorty_relay&id=$1
So the input on the browser should be domainA.com/f7g6f87g and it should make a background redirection to domainB.com/public.php?service=shorty_relay&id=f7g6f87g, but keep the domain on the browser as is.
My virtual host lines are:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/dir
ServerName domainA.com
ServerAlias www.domainA.com
ProxyPass / https://domainB.com/public.php?service=shorty_relay&id=$1
ProxyPassMatch ^/([A-Za-z0-9]{4,12})$ https://domainB.com/public.php?service=shorty_relay&id=$1
ProxyPassReverse / https://domainB.com/public.php?service=shorty_relay&id=$1
ErrorLog /var/www/dir/error.log
</VirtualHost>
With the current lines Im able to redirect the domainA.com to the root of domainB.com. But its not what I need. I need the domainA.com to accept only valid ids (?service=shorty_relay&id=$1) I know somehow I have to combine this regex so I can allow only valid id.
ProxyPassMatch ^/([A-Za-z0-9]{4,12})$ https://domainB.com/public.php?service=shorty_relay&id=$1
Any clues how can I make this possible. Im trying to figure this out days now but no luck.
Upvotes: 0
Views: 112
Reputation: 143856
Get rid of the ProxyPass
line. That line works similar to the Redirect
directive of mod_alias. It means anything after the /
automatically gets appended to the end of the target URL, excluding query strings. That means $1
has no bearing in this directive because you're not using a regular expression to capture a match.
The only thing you should need is your ProxyPassMatch
line:
ProxyPassMatch ^/([A-Za-z0-9]{4,12})$ https://domainB.com/public.php?service=shorty_relay&id=$1
Additionally, you don't need to include the query string in the ProxyPassReverse
. This directive is used to "reverse" map redirects sent from domainB.com to a matching URL in domainA.com. So this should be enough:
ProxyPassReverse / https://domainB.com/public.php
Upvotes: 1