コンテンツにスキップ

ブログアーカイブのURLを書き換える

URL形式を新しい形式`/posts///

/`に書き換える変換ルールを作成します。</p> </div> </div> </div> <div class="content-panel astro-7nkwcw3z"> <div class="sl-container astro-7nkwcw3z"> <starlight-image-zoom class="astro-vjux6bgf"> <template class="astro-vjux6bgf"> <dialog class="starlight-image-zoom-dialog astro-vjux6bgf"> <button aria-label="Unzoom image" class="starlight-image-zoom-control astro-vjux6bgf"> <svg aria-hidden="true" fill="currentColor" viewBox="0 0 24 24" class="astro-vjux6bgf"> <use href="#starlight-image-zoom-icon-unzoom" class="astro-vjux6bgf"></use> </svg> </button> <figure class="astro-vjux6bgf"></figure> </dialog> </template> <svg xmlns="http://www.w3.org/2000/svg" style="display:none" class="astro-vjux6bgf"> <symbol id="starlight-image-zoom-icon-zoom" viewBox="0 0 24 24" class="astro-vjux6bgf"> <path d="M9.79 12.79 4 18.59V17a1 1 0 0 0-2 0v4a1 1 0 0 0 .08.38 1 1 0 0 0 .54.54A1 1 0 0 0 3 22h4a1 1 0 0 0 0-2H5.41l5.8-5.79a1 1 0 0 0-1.42-1.42ZM21.92 2.62a1 1 0 0 0-.54-.54A1 1 0 0 0 21 2h-4a1 1 0 0 0 0 2h1.59l-5.8 5.79a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0L20 5.41V7a1 1 0 0 0 2 0V3a1 1 0 0 0-.08-.38Z" class="astro-vjux6bgf"></path> </symbol> <symbol id="starlight-image-zoom-icon-unzoom" viewBox="0 0 24 24" class="astro-vjux6bgf"> <path d="M21.71 2.29a1 1 0 0 0-1.42 0l-5.79 5.8V6.5a1 1 0 0 0-2 0v4a1 1 0 0 0 .08.38 1 1 0 0 0 .54.54 1 1 0 0 0 .38.08h4a1 1 0 0 0 0-2h-1.59l5.8-5.79a1 1 0 0 0 0-1.42ZM10.88 12.58a1 1 0 0 0-.38-.08h-4a1 1 0 0 0 0 2h1.59l-5.8 5.79a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l5.79-5.8v1.59a1 1 0 0 0 2 0v-4a1 1 0 0 0-.08-.38 1 1 0 0 0-.54-.54Z" class="astro-vjux6bgf"></path> </symbol> </svg> </starlight-image-zoom> <div class="sl-markdown-content astro-cedpceuv"> <p>URL形式<code dir="auto">/posts/<YYYY>-<MM>-<DD>-<TITLE></code>に従うブログアーカイブのURLを新しい形式<code dir="auto">/posts/<YYYY>/<MM>/<DD>/<TITLE></code>に書き換えるために、以下の書き換えURLルールを作成します:</p> <article class="card sl-flex astro-v5tidmuc"> <p class="title sl-flex astro-v5tidmuc"> <span class="astro-v5tidmuc"></span> </p> <div class="body astro-v5tidmuc"> <p><strong>Expression Editor</strong>のテキスト:</p><div class="expressive-code"><link rel="stylesheet" href="/_astro/ec.jmw5e.css"><script type="module" src="/_astro/ec.8zarh.js"></script><figure class="frame not-content"><figcaption class="header"></figcaption><pre data-language="txt"><code><div class="ec-line"><div class="code"><span style="--0:#eeffff;--1:#62676a">http.request.uri.path ~ "^/posts/[0-9]+-[0-9]+-[0-9]+-.*"</span></div></div></code></pre><div class="copy"><button title="Copy to clipboard" data-copied="Copied!" data-code="http.request.uri.path ~ "^/posts/[0-9]+-[0-9]+-[0-9]+-.*""><div></div></button></div></figure></div><p><strong>Path</strong> > <strong>Rewrite to…</strong> > _Dynamic_の後のテキスト:</p><div class="expressive-code"><figure class="frame not-content"><figcaption class="header"></figcaption><pre data-language="txt"><code><div class="ec-line"><div class="code"><span style="--0:#eeffff;--1:#62676a">regex_replace(http.request.uri.path, "^/posts/([0-9]+)-([0-9]+)-([0-9]+)-(.*)$", "/posts/${1}/${2}/${3}/${4}")</span></div></div></code></pre><div class="copy"><button title="Copy to clipboard" data-copied="Copied!" data-code="regex_replace(http.request.uri.path, "^/posts/([0-9]+)-([0-9]+)-([0-9]+)-(.*)$", "/posts/${1}/${2}/${3}/${4}")"><div></div></button></div></figure></div> </div> </article> <style> .card { gap: 0 !important; } </style> <p>関数<code dir="auto">regex_replace()</code>は、正規表現のキャプチャグループを使用してURLの一部を抽出することもできます。正規表現の一部を括弧で囲むことでキャプチャグループを作成します。次に、置換文字列内で<code dir="auto">${<NUMBER>}</code>を使用してキャプチャグループを参照します。ここで、<code dir="auto"><NUMBER></code>はキャプチャグループの番号です。</p> </div> <footer class="sl-flex astro-3yyafb3n"> <div class="meta sl-flex astro-3yyafb3n"> <a href="https://github.com/cloudflare/cloudflare-docs/edit/production/src/content/docs/rules/transform/examples/rewrite-archive-urls-new-format.mdx" class="sl-flex astro-eez2twj6"><svg aria-hidden="true" class="astro-eez2twj6 astro-c6vsoqas" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg> ページを編集</a> </div> </footer> <div class="items-center flex flex-wrap"><a href="https://dash.cloudflare.com/?to=/:account/:zone/rules" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Cloudflare Dashboard</span></a><a href="https://discord.cloudflare.com" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Discord</span></a><a href="https://community.cloudflare.com" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Community</span></a><a href="https://www.cloudflare.com/learning/" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Learning Center</span></a><a href="/support/contacting-cloudflare-support/" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Support Portal</span></a><div class="mx-2 my-2 text-xs text-black dark:text-white underline decoration-accent-600 dark:decoration-accent-200"><script src="https://ot.www.cloudflare.com/public/vendor/onetrust/scripttemplates/otSDKStub.js" type="text/javascript" charset="UTF-8" data-domain-script="b1e05d49-f072-4bae-9116-bdb78af15448"></script><script type="text/javascript">function OptanonWrapper() {}</script><span class="DocsFooter--content-additional-wrapper astro-hwxmvrii"> <!-- OneTrust Cookies Settings button start --> <a role="button" id="ot-sdk-btn" class="ot-sdk-show-settings astro-hwxmvrii">Cookie Settings</a> <!-- OneTrust Cookies Settings button end --> </span> </div></div> </div> </div> </main> </div> </div> </div> </div> </body></html>