Eric
Eric

Reputation: 1261

apache redirect with query string

I'm trying to do a redirect if a user goes to (the book_id and course_id numbers aren't constant):

www.mydomainname.com/admin_stuff/add_student.php?book_id=20&course_id=30

to a secure link using:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^book_id=([0-9]*)&course_id=([0-9]*)$  
RewriteRule add_student.php https://mydomainname.com/admin_stuff/add_student.php?%1 [R=301,L]

where the redirect is placed in an .htaccess file inside of the admin_stuff folder.

While a redirect occurs, it goes to:

https://mydomainname.com/admin_stuff/add_student.php?1

instead of

https://mydomainname.com/admin_stuff/add_student.php?book_id=20&course_id=30

Any help pointing me in the right direction would be appreciated.

Upvotes: 1

Views: 119

Answers (1)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

Change your .htaccess code to

RewriteEngine on

RewriteCond %{QUERY_STRING} ^book_id=([0-9]*)&course_id=([0-9]*)$ [NC]
RewriteRule add_student.php https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]

This makes sure that nothing else about the URL gets changed except its protocol.

Upvotes: 1

Related Questions