7 Years
Discussion Span
Last Post by FlashCreations

Well the most basic way in PHP would be to simply use the header function to report the 301 and then notify the user of the new location. That can be done like so:

//301 Redirect
header('HTTP/1.1 301 Moved Permanently'); 
header('Location: http://sub.domain.com/index.php?product='.urlencode($_GET['product'])); 

Though, if you want every query in the form of index.php?product= to be redirected to the subdomain, htaccess is your best choice. If you have it enabled, use it over PHP if at all possible since the rules in it are executed before PHP parses and runs any scripts. What you are looking for can be done with:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index.php?product=(.*)$ http://sub.domain.com/index.php?product=$1 [L,R=301]

EDIT: DaniWeb bug above? I set the code type in the above tag to htaccess. Are unknown types being defaulted to PHP or is there some kind of language detector (if so, .ht files look nothing like PHP source)?

Edited by FlashCreations: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.