Forum Moderators: phranque
RewriteRule ^(new-products)\/$ /products/newproducts.php? [L]
So naturally I want to use a 301 redirect to a www.mysite.com/new-products/
I tried like this:
redirectMatch 301 /products/newproducts.php www.mysite.com/new-products/
RewriteRule ^(new-products)\/$ /products/newproducts.php? [L]
RewriteRule ^(new-products)\/$ /products/newproducts.php?fr=$1 [L]
I added the GET code for rewritten part.
In PHP:
$fr = $_GET['fr'];
if($fr==""){
header("HTTP/1.1 301 Moved Permanently");
header("Location: www.mysite.com/new-products/");
exit();
}
Basically it checks if the page is already rewritten or not. If not, it redirects to a rewritten one by using 301 redirect.
No loop there, but how can I accomplish this only with .htacces code, without php?
Also, is "HTTP/1.1 301 Moved Permanently" ok to redirect single pages like that?
RewriteCond to check THE_REQUEST so that you only rewrite if the request was a direct client request. Make sure that you also change your redirect to use a
RewriteRule with the [R=301,L] flags. That is, don't mix rules from Mod_Alias and Mod_Rewrite here.
There's hundreds of prior examples in this forum.
Also, you do not need to escape the slash in the pattern.