Piyush Shrivastava
Piyush Shrivastava

Reputation: 3

301 .htaccess redirection apache server

So I am having issue I want all requests from

https://transfinmedia.com/author?url=akchopra1-A268

to be 301 redirected on

https://transfinmedia.com/author/akchopra1-A268

but when i use

RewriteEngine on
RewriteCond %{QUERY_STRING} url=(.*) 
RewriteRule ^author(.*) /author/%1 [L,R=301,NC]

requests to

https://transfinmedia.com/author?url=akchopra1-A268 gets redirected on

https://transfinmedia.com/author/akchopra1-A268?url=akchopra1-A268

what am i doing wrong here, completely out of clue.

Upvotes: 0

Views: 23

Answers (2)

Amit Verma
Amit Verma

Reputation: 41219

By default ,mod-rewrite appends old QueryString to the new target url. To discard QueryString ,you need to put a ? (an empty question mark) at the end of the target url.

RewriteEngine on
RewriteCond %{QUERY_STRING} url=(.*) 
RewriteRule ^author(.*) /author/%1? [L,R=301,NC]

Make sure to clear your browser cache before using this.

Upvotes: 1

Matt.G
Matt.G

Reputation: 3609

change RewriteRule to

RewriteRule ^author\?url=(.*)$ /author/%1 [L,R=301,NC]

Demo

Upvotes: 0

Related Questions