Mohammad Mirzadeh
Mohammad Mirzadeh

Reputation: 309

redirect old url with .htaccess

I have a website, example: example.com

I want to redirect with .htaccess a url to b url:

a: /global/index.php?option=about b: /news/group/13/

I test & search many times but no result!

this is my code:

RewriteEngine on

RedirectMatch ^(.*)about(.*)$  http://example.com/news/group/13/$1

RedirectMatch ^/global/index.php?option=about$  http://example.com/news/group/13/$1

RedirectMatch ^/index.php?option=about$  http://example.com/news/group/13/$1

Redirect permanent /global/index.php?option=about example.com/news/group/13/

Upvotes: 1

Views: 25

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

option=about is part of querystring in your url and you can not test it using RedirectMatch pa and Redirect directive. You need to capture it using %{QUERY_STRING} variable

RewriteEngine on


RewriteCond %{QUERY_STRING} ^option=about$
RewriteRule ^ /news/group/13? [L,R]

An empty question mark ? at the end of the destination path is important as it discards the old querystring from new url.

Upvotes: 1

Related Questions