0

In my .htaccess I'm trying to redirect the following page:

/category/item?id=81

To the following URL:

/category

This is where I got to far (it's at the top of my mod rewrites):

  RewriteCond %{REQUEST_URI}  ^/category/item$
  RewriteCond %{QUERY_STRING} ^id=81$
  RewriteRule ^(.*)$ http://mywebsite/category? [L,R=301]

However it's not redirecting the page. Just wondering if there's anything I need to add to this to get it to work?

3
  • Probably the url or the query string does not end with the given pattern. Remove the $ to search from the beginning of the string only, instead of the whole string (until it ends) Commented Jun 15, 2018 at 5:53
  • Your rule works fine for me. Try clearing your browser cache or use a different browser to test the url. Commented Jun 15, 2018 at 6:00
  • Also adding RewriteEngine on might help Commented Jun 15, 2018 at 7:24

2 Answers 2

1

Try it like this:

RewriteCond %{QUERY_STRING}  ^id=81$ [NC]
RewriteRule ^category/item$ /category? [R=301,NE,NC,L]

or

RewriteCond %{QUERY_STRING}  ^id=81$ [NC]
RewriteRule ^category/item$ http://mywebsite//category? [R=301,NE,NC,L]

Use a fresh browser in incognito mode to test it.

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

1 Comment

Thank you for this :) I managed to get a solution working shortly after I posted my question (see below), but these are helpful to know for the future
0

This did the trick for me (I solved it before the answers above were posted):

RewriteCond %{REQUEST_URI}  ^/category/item$
RewriteCond %{QUERY_STRING} ^id=81
RewriteRule ^(.*)$ category? [L,R=301]

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.