1

trying to redirect a url with ending parameter to same url without that parameter on the same domain

www.mydomain.com/efg/abc?id=303
to
www.mydomain.com/efg/abc

found this answer on the matter and try to use it but it doesn't work for me:

RewriteCond %{HTTP_HOST}  ^mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} /efg/abc
RewriteRule ^efg/abc? [L,R=302]

would appreciate any help.thanks

2 Answers 2

1

You can use this rule:

RewriteCond %{QUERY_STRING} ^id=303$ [NC]
RewriteRule ^efg/abc/?$ %{REQUEST_URI}? [NC,L,R=302]

? at the end of target URI will strip off any previous query string.

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

1 Comment

hi @anubhava, is this rule specific to www.mydomain.com/efg/abc?id=303 ? i need it to be specific. so that other url's ending with "id=" are not effected...
0

You will basically want to drop the query string. The last line you have with the abc? is not correct because it doesn't redirect anywhere.

Here is what should do the trick (this line alone and be sure that you have enabled modrewrite in .htaccess already):

RewriteRule ^efg/abc$ /efg/abc? [L,R=301]

I tested the above on a test domain of mine and it did the trick.

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.