Jump to content

301 Redirect + Seo Urls Problem In Htaccess


mdedens

Recommended Posts

Hi,

 

I appreciate anyone that could offer advice on this, or even a link to someplace I could not find yet with more info.

 

I'm using a friends custom gallery script, which currently has an htaccess file that looks like this:

 

>
AddType application/x-httpd-php .php .html 
AddType application/x-httpd-php .php .shtml

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_Host} ^****.com [NC] 
RewriteRule ^(.*)$ [url="http://www.****.com/$1"]http://www.****.com/$1[/url] [L,R=301]

RewriteRule (.*)_(.*)_(.*)_(.*)_(.*)\.php$ /products/index.php?productName=$1&product=$2&photo=$3&C=$4&sc=$5
RewriteRule (.*)_(.*)_(.*)_(.*)\.php$ /products/index.php?subCategoryName=$1&cat=$2&subcat=$3&page=$4
RewriteRule (.*)_(.*)_(.*)\.php$ /products/index.php?subCategoryName=$1&cat=$2&subcat=$3
RewriteRule (.*)_(.*)\.php$ /products/index.php?categoryname=$1&cat=$2

 

I added a 301 redirect from an old page to a new page, but it doesn't seem to be working correctly.

 

Here is the code I added to the top of the htaccess file for the 301 redirect. (sconses was spelled wrong, and the pages are created on fly via the code above... based on whatever the title of the product is in the database, I think)

 

>redirect 301 /products/Wall-Sconses_2_4.php [url="http://www.****.com/products/Wall-Sconces_2_4.php"]http://www.****.com/products/Wall-Sconces_2_4.php[/url]

 

Now when I go to the old page, it redirects incorrectly to this:

 

>http://www.****.com/products/Wall-Sconces_2_4_1.php?subCategoryName=products/Wall-Sconses&cat=2&subcat=4

 

The above URL actually works in terms of the page not being broken, but it adds that unwanted second part.

 

>?subCategoryName=products/Wall-Sconses&cat=2&subcat=4

 

The problem is since both URLs technically work, I didn't want to get hit for a duplicated content page. (There are multiple redirects/pages like this.) So basically, anyone know how I can get the redirect to stop adding that extra URL code?

 

Any help is much appreciated. Thanks for your time.

Edited by mdedens
Link to comment
Share on other sites

Are you just wanting to strip off the query string? If so, I think this should work. Add it somewhere below "RewriteEngine On"

 

>RewriteRule ^products/Wall-Sconses_2_4.php /products/Wall-Sconces_2_4.php? [R=301,NC]

Link to comment
Share on other sites

Hi click,

 

I appreciate you trying this out, you are correct in what I'd like to have happen.

 

Do I have to keep the 301 redirect code?

 

I tried with and without, and in different orders, but still can't seem to get it to work. Maybe it is because the pages are built in the htaccess file? Although I guess that shouldn't matter.

 

Here is what I have now, but still getting the string on the end. (I tried removing the 301 redirect part, but then the page is just a 404 error page.)

 

>AddType application/x-httpd-php .php .html 
AddType application/x-httpd-php .php .shtml

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_Host} ^****.com [NC] 
RewriteRule ^(.*)$ [url="http://www.****.com/$1"]http://www.****.com/$1[/url] [L,R=301]

RewriteRule (.*)_(.*)_(.*)_(.*)_(.*)\.php$ /products/index.php?productName=$1&product=$2&photo=$3&C=$4&sc=$5 [L]
RewriteRule (.*)_(.*)_(.*)_(.*)\.php$ /products/index.php?subCategoryName=$1&cat=$2&subcat=$3&page=$4 [L]
RewriteRule (.*)_(.*)_(.*)\.php$ /products/index.php?subCategoryName=$1&cat=$2&subcat=$3 [L]
RewriteRule (.*)_(.*)\.php$ /products/index.php?categoryname=$1&cat=$2 [L]

RewriteRule ^products/Wall-Sconses_2_4.php /products/Wall-Sconces_2_4.php? [R=301,NC]

redirect 301 /products/Wall-Sconses_2_4.php [url="http://www.****.com/products/Wall-Sconces_2_4.php"]http://www.****.com/products/Wall-Sconces_2_4.php[/url]

Link to comment
Share on other sites

I wonder if there is some type of server or php config problem. I arranged everything accordingly but just get a blank white page in Firefox. And the IE 404 error page when visiting in IE. So basically just a 404 error page.

 

I don't mean to overwhelm with this, but I thought maybe it would be helpful to post some code that appears in the products/index.php page that generates every other page under the products dir. It may be that the long way has been taken to creating 404 error pages and may be preventing redirects. (This all appears before the HEAD tag) Maybe something is familiar or obvious?

 

(the call to the config file is just for connecting to the db, it contains username, pw, etc.)

 

I appreciate the time you spend on this, don't stress if it gets to be too much.

 

><? 

/*if (!ini_get("register_globals")){
  		foreach ($_REQUEST as $k=>$v){
    	  if (!isset($GLOBALS[$k])){
        	  ${$k}=$v;
      		}
  		}
}*/
$productName = isset($_GET["productName"]) ? $_GET["productName"] : "";
$product = isset($_GET["product"]) ? $_GET["product"] : "";
$photo = isset($_GET["photo"]) ? $_GET["photo"] : "";
$c = isset($_GET["c"]) ? $_GET["c"] : "";
$sc = isset($_GET["sc"]) ? $_GET["sc"] : "";
$subCategoryName = isset($_GET["subCategoryName"]) ? $_GET["subCategoryName"] : "";
$cat = isset($_GET["cat"]) ? $_GET["cat"] : "";
$subcat = isset($_GET["subcat"]) ? $_GET["subcat"] : "";
$page = isset($_GET["page"]) ? $_GET["page"] : "";
$categoryname = isset($_GET["categoryname"]) ? $_GET["categoryname"] : "";


require("../config/config.php");

if(!($link = @mysql_connect ($hostType, $dbUser, $dbPassword)))
       echo "cannot connect to database" . mysql_error();
 else {
       mysql_select_db ($dbName)
            or exit("cannot select" . mysql_error());
      }
   
if($cat && $subcat)
{
$catquery404 = mysql_query("SELECT * FROM category WHERE catID=$cat");	   
$cat404 = mysql_num_rows($catquery404);	
$subquery404 = mysql_query("SELECT * FROM subcat WHERE subID=$subcat");	   
$subcatTitle = mysql_fetch_array($subquery404);

$subcatName404 = "products/";
$replaceChars404 = array(" ", "'", ":", "/", ",", "&", "---", "&", "--");
$subcatN404 = str_replace($replaceChars404, "-", $subcatTitle["subName"]);
$subcatName404 .= str_replace($replaceChars404, "-", $subcatN404);

//echo $subCategoryName."<br />";
//echo $subcatName404;
if($subCategoryName != $subcatName404)
{
	header("HTTP/1.1 404 Not Found");
	exit;
}


$sub404 = mysql_num_rows($subquery404);	
if($cat404 == 0 || $sub404 == 0)
{
	header("HTTP/1.1 404 Not Found");
	exit;
}
}
else if($product && $photo)
{
//echo $productName."<br>";

$productError = mysql_query("SELECT products.productID, products.catID, products.subID, information.pageDesc FROM products,information WHERE products.productID = $product AND information.productID = $product");
$productRow = mysql_num_rows($productError);
$photoError = mysql_query("SELECT photoID FROM photo WHERE photoID = $photo");
$photoRow = mysql_num_rows($photoError);
	
$productErrorRes = mysql_fetch_array($productError);
$photoErrorRes = mysql_fetch_array($photoError);

$productName404 = "products/";
$replaceChars404 = array(" ", "'", ":", "/", ",", "&", "---", "&", "--");
$productN404 = str_replace($replaceChars404, "-", $productErrorRes["pageDesc"]);
$productName404 .= str_replace($replaceChars404, "-", $productN404);

//$productName404 .= "_".$productErrorRes["productID"]; //."_".$photoErrorRes["photoID"]."_".$productErrorRes["catID"]."_".$productErrorRes["subID"];

//echo $productName404;
if($productName != $productName404)
{
	header("HTTP/1.1 404 Not Found");
	exit;
}

if($productRow == 0 || $photoRow == 0)
{
	header("HTTP/1.1 404 Not Found");
	exit;
}
}
else if($cat)
{

$catquery404 = mysql_query("SELECT * FROM category WHERE catID=$cat");	   
$catTitle = mysql_fetch_array($catquery404);
$cat404 = mysql_num_rows($catquery404);	

$catName404 = "products/";
$replaceChars404 = array(" ", "'", ":", "/", ",", "&", "---", "&", "--");
$catN404 = str_replace($replaceChars404, "-", $catTitle["catName"]);
$catName404 .= str_replace($replaceChars404, "-", $catN404);

//echo $categoryname."<br />";
//echo $catName404;
if($categoryname != $catName404)
{
	header("HTTP/1.1 404 Not Found");
	exit;
}

if($cat404 == 0)
{
	header("HTTP/1.1 404 Not Found");
	exit;
}
}
?>


<?
$navSelect = mysql_query("SELECT * FROM category ORDER BY catID");	
?>

<? 
//META DESCRIPTION CONTENT
if($product && $photo)
{
$metaQuery = mysql_query("SELECT pageDesc,metaDesc FROM information WHERE productID=$product");
$metaResult = mysql_fetch_array($metaQuery);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

Link to comment
Share on other sites

Does it work if you just type the address you're redirecting to into the address bar? What URL is it trying to open when it generates the 404? I notice that your redirect refered to "Wall-Sconses_2_4.php " but later you said it redirects to "Wall-Sconces_2_4_1.php". Is that a typo in the redirect maybe? "RewriteRule ^products/Wall-Sconses(.*)\.php /products/Wall-Sconces$1.php? [R=301,NC]" should take care of anything beginning with "Wall-Sconses".

Link to comment
Share on other sites

I tried creating products/Wall-Sconses.php today, (thought maybe adding a header redirect would work), but the page itself doesn't even show up in the browser when I go to the URL.

 

I removed all redirects, and the header redirect, added some text to the page, but when I go to the URL it's still just a blank white page, aka 404 error.

 

Does this offer any insight into what could possibly be wrong?

 

Maybe it is those other re-write rules in the htaccess... If anybody knows where I can go to get help with this, I can see about compensation for figuring this out.

Link to comment
Share on other sites

New info...

 

I tried adding this to the htaccess... added the L,

 

>RewriteRule ^products/Wall-Sconses_2_4.php /products/Wall-Sconces_2_4.php? [L, R=301,NC]

 

And when I go to any page in the gallery it throws a 500 Internal Server error. Is this info in any way helpfully diagnostic?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...