I am trying to redirect one complete URL
But this is not working ...
RewriteCond %{HTTP_HOST} ^https://www.moccioso.com/d.php? id=ultimateselection.zip$ RewriteRule ^$ http://moccioso.com/sd_product/ultimateselection-zip [L,R=301]
(I'm assuming you've not wrapped the code onto multiple lines in your actual code?)
The HTTP_HOST
variable contains the Host
HTTP request header. ie. the hostname specified on the request eg. www.example.com
only - there is no scheme, URL-path or query string here. So, this RewriteCond
directive will never match.
But you are also trying to match an empty URL-path with the RewriteRule
pattern ^$
- so again, this will never match. In your example the URL-path is /d.php
. The RewriteRule
pattern matches against the URL-path only.
You are also redirecting to http
(not https
) in this directive? Your example uses https
. You are also removing the www
subdomain, but again, your example includes it?
If you are redirecting from/to the same hostname and only have one domain then you don't need to explicitly include the domain name (ie. the requested hostname) in the rule.
To match against the query string you need to match against the QUERY_STRING
server variable.
Try the following instead, near the top of your .htaccess
file.
RewriteCond %{QUERY_STRING} ^id=ultimateselection\.zip$
RewriteRule ^d\.php$ /sd_product/ultimateselection-zip [R=301,L]
This will need to go near the top of your .htaccess
file. Test first with a 302 (temporary) redirect to avoid potential caching issues.
Clear your browser cache before testing.