Forum Moderators: phranque

Message Too Old, No Replies

Setup redirect

         

mrpietersen

8:49 pm on Jun 29, 2020 (gmt 0)

5+ Year Member



Hi all, i am looking for help to setup redirects in htacces. Somehow it does not work out.

i want to redirect http://www.example.com/?md
to
http://www.example.com/newurl/

can somebody help me out?

phranque

9:16 pm on Jun 29, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], mrpietersen!

can somebody help me out?

what have you tried so far and what were the results?

Somehow it does not work out.

please describe this in more detail.
look for clues in your web server access and error log files.

lucy24

10:41 pm on Jun 29, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i want to redirect
Do you mean only this one specific redirect, or do you mean that
blahblah?some-exact-query

is to be redirected to
some-new-queryless-url
?

mrpietersen

7:19 am on Jun 30, 2020 (gmt 0)

5+ Year Member



I want to redirect an exact match with the url.
So http://example.com/declareren/?md needs to be redirected to http://example.com/declareren/

So an url with a query to a queryless one.

I already tried: Redirect 301 /declareren/?md http://example.com
does not work obviously.

also tried it with redirect condition. But I can't find the correct setup for this. something like below, but all documentation is about query strings in the URL (like ?id=123)

RewriteCond %{QUERY_STRING} ^id=1$
RewriteRule ^page.php$ http://www.example.com/content/page? [R=301,L]

mrpietersen

12:15 pm on Jun 30, 2020 (gmt 0)

5+ Year Member



I managed to fix it. this worked (where key=value is the query string, everything after the ?):

# Redirect Query String
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/specific/url/
RewriteCond %{QUERY_STRING} key=value
RewriteRule (.*) /path/ [R=301,L]
</IfModule>

phranque

1:46 pm on Jun 30, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



- you can make things more efficient by testing the URI string in the RewriteRule.
the Pattern of the RewriteRule is tested before any RewriteCond directives are run.

- for a 301 redirect, the Substitution string should contain the full protocol and hostname.

- end the Substitution string with a question mark to erase the existing query string from the redirected url

- the <IfModule mod_rewrite.c> envelope is unnecessary in your environment since you already know you have mod_rewrite installed.

# Redirect Query String
RewriteCond %{QUERY_STRING} key=value
RewriteRule ^specific/url/$ http://www.example.com/path/? [R=301,L]