1

I want to redirect specific URL with params to another domain

http://domain.tld/buy/?w=X1234 to http://anotherdomain.tld/product.php?id=X1234

Here my htaccess

RewriteCond %{REQUEST_URI} !^/*buy/(.*)$ [NC]
RewriteRule ^/*buy/?w=([a-zA-Z0-9]+)$ http://anotherdomain.tld/product.php?id=$1 [NC,L,R=301]

but not working. maybe the problem is param ?w=

Thank you

UPDATE: i solve the problem by using Query string, after reading How to REGEX and .htaccess rewrite url

RewriteCond %{QUERY_STRING} ^w=([a-zA-Z0-9]+)$
RewriteRule ^/*buy/$ http://anotherdomain.tld/product.php?id=%1 [NC,L,R=301]

Thank you stackoverflow and folks! i m start understanding regex from here ^_^

1 Answer 1

0

That's right, your params won't be picked up, but they can be passed on.

Something like;

RewriteRule ^buy/([a-zA-Z0-9]+)$ http://anotherdomain.tld/product.php?id=$1 [NC,L,R=301]

Where your original url would be; /buy/X1234

Sign up to request clarification or add additional context in comments.

1 Comment

I m not allowed to change the w params. How to make ?w= as string in htaccess regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.