3

I have a Forum on my site and need to redirect weirdly generated urls.

Every url contains ?id=, eg:

https://www.example.com/forum/topic/casualthread/page/25?id=casualthread

and I need to remove the ?id= and everything that follows in order to have:

https://www.example.com/forum/topic/casualthread/page/25

I am trying to modify this code I found here on Stackoverflow with very scarce results:

RewriteEngine On
RewriteBase /
# Make sure there is a query string
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*  /?id= [R=301,L]

The htaccess file i am editing is in the forum directory: https://www.example.com/forum/

and it redirects everything to the homepage https://www.example.com: what am I doing wrong?

1
  • 1
    No, google only found those I mentioned. Starkeen answer did the trick. Commented May 24, 2018 at 15:46

2 Answers 2

2

You can use this

RewriteEngine on


RewriteCond %{QUERY_STRING} id=
RewriteRule ^ %{REQUEST_URI}? [L,R]
Sign up to request clarification or add additional context in comments.

Comments

0

Since not just id, but also some other parameter(s) may be present in the query string, use:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^(.*)(^id=[^&]*&?|&id=[^&]*)(.*)$
RewriteRule ^(.+) /$1?%1%3 [R=301,L]

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.