それは
http://www.website.com/product/sony-tv-42-inch
から
http://www.website.com/product/sony-tv-42-inch
にあなたは再書き込みをするためにかなり容易になるだろうが、余分な/提示しようとしていること問題。
SEOの目的で301がほしいと思っているので、ここで私は何をしますか?
ステップ1 - 現在のURLを取得する:
は、現在のすべてのポストパーマリンクのリストを取得します。 David GeorgeでMySQLのこのSQLクエリは、トリックを行う必要があります。
SELECT wpp.post_title,
wpp.guid,
wpp.post_date,
CONCAT
(
wpo_su.option_value,
REPLACE
(
REPLACE
(
REPLACE
(
REPLACE
(
wpo.option_value,
'%year%',
date_format(wpp.post_date,'%Y')
),
'%monthnum%',
date_format(wpp.post_date, '%m')
),
'%day%',
date_format(wpp.post_date, '%d')
),
'%postname%',
wpp.post_name
)
) AS permalink
FROM wp_posts wpp
JOIN wp_options wpo
ON wpo.option_name = 'permalink_structure'
AND wpo.blog_id = 0
JOIN wp_options wpo_su
ON wpo_su.option_name = 'siteurl'
AND wpo_su.blog_id = wpo.blog_id
WHERE wpp.post_type = 'post'
AND wpp.post_status = 'publish'
ORDER BY wpp.post_date DESC
ステップ2 - 後でそれを保存します。後でのためのExcelの列にそれをダンプ今、あなたはそのリストを持っていることを 。
ステップ3 - PHP用にフォーマットします。 すべてのURLを取り、Notepad ++または同等のものにダンプします。ウィンドウでは、検索/置換機能を呼び出すためにcntrl + Hを押してください。 「検索モード」を選択してください - >については
「拡張」あなたはすべてを交換して「あなたは、に入れて打つ必要があります「で置き換え」の\ rを\ nはに入れなければならない「とは何の検索」 '
すべてのURLのリストがカンマで区切られているはずです。
ステップ4 - PHPファイルを作成します - .htaccessの
上からあなたの出力が見えるはずです5
<?php
$urlString = "http://www.urlsample1.com/article/sony-thing-and-stuff, http://www.urlsample1.com/article/warner-brothers-stuff";
//this will replace the word article with the word product
$newstring = str_replace("article", "product", $urlString);
//turns string into array
$myArray = explode(',', $newstring);
//loops through array to find first case of - and turn it to a/
for ($i = 0; $i < count($myArray); ++$i) {
$haystack = $myArray[$i];
$needle = "-";
$replace = "/";
$pos = strpos($haystack, $needle);
if ($pos !== false) {
$finalstring = substr_replace($haystack, $replace, $pos, strlen($needle));
}
//removes common url elements
$newShort = str_replace("http://www.urlsample1.com", "", $finalstring);
$oldShort = str_replace("http://www.urlsample1.com/product", "/article", $myArray[$i]);
//prints out the old and new url in .htaccess format
print("Redirect 301 " . $oldShort . " " . $newShort . "</br>");
};
?>
ステップ:
新しいPHPファイルを作成し、設定をlike:
Redirect 301 /product/sony-thing-and-stuff /product/sony/thing-and-stuff
Redirect 301 /product/warner-brothers-stuff /product/warner/brothers-stuff
であり、.htaccessファイルに入れることができます。
注:この方法はApacheでは遅くなる可能性がありますが、それは好ましくありませんが、クライアントを新しい状況で立ち上げるためには、私が考えることができる最も簡単な方法です。
また、Regexを使用して1回のリダイレクトから処理することもできます。記事を選択してそれを 'product'に変更するには\/[article] {1、} \ /になりますが、Regexが ' - 'の最初のインスタンスのみを処理し、それらのすべてを選択しないことはわかりません。だから私はこの方法を選んだのです。 regexにもっと慣れているなら、1回の書き換えルールを実行できます。 – AdamSC