apache使用查询字符串重定向


apache redirect with query string

如果用户转到(book_id和course_id数字不是恒定的):,我将尝试进行重定向

www.mydomainname.com/admin_stuff/add_student.php?book_id=20&课程id=30

到安全链接使用:

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]

重定向位于admin_stuff文件夹内的.htaccess文件中。

当重定向发生时,它转到:

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

而不是

https://mydomainname.com/admin_stuff/add_student.php?book_id=20&课程id=30

如果能为我指明正确的方向,我们将不胜感激。

.htaccess代码更改为

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]

这样可以确保除了协议之外,URL的其他任何内容都不会被更改。