3

I need to redirect

http://example.com/page/?Id=1253-23098-

to

http://example.com/page/1253-23098

This redirection also includes removal of '-' from end of query string.

What i've done is

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/page/$
RewriteCond %{QUERY_STRING} ^Id=([0-9\-\0-9]*)$
RewriteRule ^(.*)$ http://example.com/page/%1? [L,R=301]

which is redirecting me to

http://example.com/page/1253-23098-

I need to removed anything after "1253-23098" from my query string.

I've googling it from last 3-4 hours buts nothing seems to work. Any help is appreciated.

Praveen Dabral
  • 2,449
  • 4
  • 32
  • 46

2 Answers2

1

Try :

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/page/?$
RewriteCond %{QUERY_STRING} ^Id=([0-9]*)-([0-9]*)-$ 
RewriteRule ^(.*)$ http://example.com/page/%1-%2? [L,R=301]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
1

You can use:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^Id=(\d+-\d+) [NC]
RewriteRule ^page/?$ page/%1? [NC,L,R=301]
Croises
  • 18,570
  • 4
  • 30
  • 47