Mohammad
Mohammad

Reputation: 111

.htaccess: Redirect url if "string" in url

I want redirect old url to new url [301]

Old url :

http://www.name.com/one/?page=2
http://www.name.com/two/?page=5
http://www.name.com/three/?page=1

New url :

http://www.name.com/one/page/2/
http://www.name.com/two/page/5/
http://www.name.com/three/page/1/

How can redirect url if ?page=X contain in url and move to /page/X/ ?

Upvotes: 2

Views: 61

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You can use the following :

RewriteEngine on


RewriteCond %{THE_REQUEST} /([^?]+)/\?page=([^\s]+) [NC]
RewriteRule ^ /%1/page/%2/? [L,R=301]

This will redirect /foo/?page=123 to /foo/page/123/

Upvotes: 1

Related Questions