Apacheの書き換えパターン正規表現

Apacheの書き換えパターン正規表現

リダイレクトする必要がある複数のURLがあり、URLには3つの主要なパターンがあります。

最初のモード タイトル URL の先頭にダッシュがありますが、-ダッシュを削除したいと思います。

www.example.com/buzz/news/the-written--malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile

www.example.com/break/news/5-kids--were-found-rigmaroling-armed  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

2番目のモード

URLの間に2つのダッシュがあるため、--1つのダッシュにのみ変更する必要があります- 。例:

www.example.com/buzz/news/-the-written-malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile

www.example.com/break/news/-5-kids-were-found-rigmaroling-armed  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

3番目のモード タイトルURLの末尾にダッシュがあり、-ダッシュを削除しようとしています。

www.example.com/buzz/news/the-written-malice-of-rdicile- www.example.com/buzz/news/the-written-malice-of-rdicile

www.example.com/break/news/5-kids-were-found-rigmaroling-armed-  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

4番目のモード URLに開始ダッシュ、デュアルダッシュ、エンドダッシュの組み合わせがあり、開始ダッシュと終了ダッシュを削除し、ダブルダッシュを単一ダッシュに変更しようとしています。

www.example.com/buzz/news/-the-written--malice-of-rdicile- www.example.com/buzz/news/the-written-malice-of-rdicile

www.example.com/break/news/-5-kids-were-found--rigmaroling-armed-  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

www.example.com/break/news/-5-kids-were-found-rigmaroling-armed-  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

これらのパターンは約5000行なので、正規表現などを使用して5000行すべてを実行し、URLにApache Rewriteを適用する方法を探しています。

助けてくれてありがとう。事前にありがとう

PS:質問をより明確にするために編集を続ける予定ですか?私に聞いてください。

全体として、左側はリダイレクトするURL、右側はユーザーが接続する必要がある最終URLです。

www.example.com/buzz/news/the-written--malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile 

www.example.com/break/news/5-kids--were-found-rigmaroling-armed  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

www.example.com/buzz/news/-the-written-malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile

www.example.com/break/news/-5-kids-were-found-rigmaroling-armed  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

www.example.com/buzz/news/-the-written--malice-of-rdicile- www.example.com/buzz/news/the-written-malice-of-rdicile

www.example.com/break/news/-5-kids-were-found--rigmaroling-armed-  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

www.example.com/break/news/-5-kids-were-found-rigmaroling-armed-  www.example.com/break/news/5-kids-were-found-rigmaroling-armed

ベストアンサー1

結局のところ、ソースとターゲットのURLは一致し、単純化または最適化するために正規表現を使用する必要はありませんでした。

1行ずつすると5000行のリダイレクトになります。

おすすめ記事