Search code examples
.htaccessurlhttp-redirectdynamictemporary

Redirect a single dynamic URL with Apache .htaccess to temporary page


Here is what I need to redirect to a temporary HTML page:

http://www.domain1.com/?Itemid=230

should get redirected to:

http://www.domain2.com/temoporary-solution.html

Here is what I came up with, just not sure if it will cause any issues between the rest of the .htaccess rules (this is the first rule):

RewriteCond %{HTTP_HOST}  ^www\.domain1\.com$ [NC]
RewriteCond %{QUERY_STRING}  ^Itemid=230$ [NC]
RewriteRule ^$ http://domain2.com/temoporary-solution.html [R=302,NE,NC,L]

Solution

  • Your rule should work fine. Just append ? at the end of target URI to strip off existing query string:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
    RewriteCond %{QUERY_STRING} ^Itemid=230$ [NC]
    RewriteRule ^$ http://domain2.com/temoporary-solution.html? [R=302,L]