Here's my situation, i think it's a unique one as far as these forums go, as i did a search and came up with nothing.
I have a website,
www.jailbeta.com (i had to register it once i saw it was available...).
Anyway, my OLD way of urls (using mod_rewrite), was site.com/article/article-text-p-(article_id_from_database).html
however, recently i realized my URLs were quite long, so i decided i would strip out stopwords from it. Wrote the function, updated all my pages, all is great.
However, now i have site.com/article/some-article-with-stopword-p-123.html
and
site.com/article/some-article-with-p-123.html
if that makes sense.
so here's what i did:
in my htaccess:
Code:
RewriteRule ^article/(.*)-p-(.*)\.html$ old-articles.php?id=$2 [L,QSA]
### changed rewrite rule with stopwords, 301 the urls that had the stopwords to the url that doesnt. ###
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^old-articles\.php$ /redirect.php$1 [R=301,L]
RewriteRule ^article/(.*)-a-(.*)\.html$ articles.php?id=$2 [L,QSA]
redirect.php has some code to get the url from the database, strip out stopwords as normal, and forward it on to site.com/article/no-stopwords-here-a-123.html
here is redirect.php:
Code:
if(isset($_GET['id'])) {
$redirID = intval($_GET['id']);
$res = run_query("SELECT articles_sanitized FROM articles WHERE articles_id = '$redirID'");
$newtitle = mysql_fetch_assoc($res);
$newurl = '/article/'.makeLink($newtitle['articles_sanitized'], $redirID);
}
if($redirID != '' && $newurl != '') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: $newurl");
exit();
} else {
die('what exactly are you trying to do here?');
}
So basically i guess what i'm asking...is this the best way to do it? Since my mod rewrite paid no attention to anything other than the id (whatever was after -p-), i couldn't do any other kind of rewrite or redirect without getting myself into an infinite loop.
I'm no seo expert, i know very little actually, just a somewhere in between beginner and advanced php developer. any help is greatly appreciated, both from SEOers and PHPers/Apache geniuses.
also, how long should i leave this 301 in tact? can i leave it forever? since now all urls will be going to /article/something-a-123.html, as opposed to previously they were going to /article/something-p-123.html, will it make any difference once the engines update everything?
Thanks
