0

I'm looking to do the opposite of a common query with .htaccess files.

I want to redirect a standard url to a url with a query string, similar to below:

test.com/directory/pagename

to:

test.com/template?id=1

I don't require pattern matching of any form, I just want to write out a separate redirect for each one. For example:

test.com/colours/red = test.com/template?id=5

test.com/colours/yellow = test.com/template?id=3

Hopefully this makes some sense.

3
  • 1
    So: What did you try? And what is wrong with your result? Commented Jul 5, 2015 at 14:36
  • I've tried a standard 301 redirect but it doesn't work with the query string. I struggle with htaccess, i don't find it very intuitive to learn. Commented Jul 5, 2015 at 14:50
  • 2
    Do you want to redirect or rewrite internally? Commented Jul 5, 2015 at 15:44

1 Answer 1

2

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^colours/yellow/?$ template?id=3 [L,NC,QSA]

RewriteRule ^colours/red/?$ template?id=5 [L,NC,QSA]
Sign up to request clarification or add additional context in comments.

Comments

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.