Htaccess GET request conflict

I have a wildcard subdomain setup on the server to get the subdomain as a variable. which works great for the root directory. Now I have a subdirectory where I need the same which works. But the problem comes when I add a query string to this subdomain. Mine .htaccess

in subdirectory example.com/student:

<IfModule mod_rewrite.c>
Options -Indexes
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}example.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]example.com$
RewriteRule ^MyCourse.php$ MyCourse.php?pageDetailId=%1 [L]

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}example.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]example.com$
RewriteRule ^MyExam.php?courseId=(0-9+)$ MyExam.php?pageDetailId=%1&courseId=$1 [L]
</IfModule>

      

MyCourse.php works great. I am not adding any query string to it, but MyExam.php requires a GET query string, required as courseId. So, no matter what I do, I get the subdomain (pageDetailId) or the course, but not both. Also, if there is a general way to get a subdomain variable across all files in a subdirectory, I will appreciate it.

+3


source to share


1 answer


In this part of the rule, just add QSA flag

and it will send query string

if one exists. You don't need to add it to the rule.

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}example.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]example.com$
RewriteRule ^MyExam.php$ MyExam.php?pageDetailId=%1 [QSA,L]

      



http://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_qsa

+3


source







All Articles