您需要檢查QUERY_STRING
作爲RewriteRule
不包括它。另外,您的規則不使用重定向標誌R
。
RewriteEngine on
# First, check for the subdomain
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [NC]
# Then, check the query string - it should match digits (\d+)
RewriteCond %{QUERY_STRING} ^dl=\d+ [NC]
# Check if we are not at subdomain.php
# (This is redundant, but leaving it here in case you really need it)
RewriteCond %{REQUEST_URI} !^/subdomain.php
# If all the above conditions are true, match a root-request
# and redirect to domain.com/subdomain.php with the query string
# Note: You don't need to actually specify the query string
# in the destination URI - Apache will automatically
# hand it over upon redirect (using the R flag).
# The only time this is not the case is when you
# either add the QSD flag, or append the destination
# URI with a question mark.
RewriteRule ^$ http://domain.com/subdomain.php [R=302,L]
上面將重定向http://subdomain.domain.com/?dl=2到http://domain.com/subdomain.php?dl=2。如果您想通過瀏覽器和搜索引擎將重定向永久化並緩存,請將302
更改爲301
。
謝謝你,正是需要什麼和一個很好的解釋。 –
非常歡迎。 –