TYPO3:RealURL与tx_news重复斜杠问题已解决但求原理
Hey there, let's break down why you were seeing those frustrating double slashes in your tx_news URLs and why adjusting the tx_news_pi1[action] configuration in RealURL fixed the issue—since you're new to PHP and TYPO3's RealURL setup, I'll keep this straightforward and practical.
The Problem Recap
When following the official tx_news docs for RealURL configuration, you encountered a URL formatting bug: URLs for news items ended up looking like
domain.com/post//post-titleinstead of the cleandomain.com/post/post-title. You tested and found that either moving thetx_news_pi1[action]entry infixedPostVarsaftertx_news_pi1[news], or deleting the action config entirely, resolved the double slash problem.
Why This Happens
RealURL processes the fixedPostVars in the exact order you list them—and that's where the issue originated. Here's the play-by-play:
- When
tx_news_pi1[action]is placed beforetx_news_pi1[news], RealURL tries to generate a URL segment for the action (like "detail") first. But in most tx_news setups, the presence of a news item ID/slug already tells TYPO3 to load the detail view automatically. This means the action parameter doesn't need a visible URL segment, so RealURL creates an empty placeholder instead. - Next, when it processes
tx_news_pi1[news](the news item's title/slug), it appends that segment right after the empty action placeholder. That empty spot translates to a double slash in the final URL. - The key point: your setup didn't actually need the explicit action segment in the URL, so keeping that config in the wrong order forced RealURL to add an unnecessary empty segment.
The Fixes (Recapped & Explained)
- Option 1: Reorder your
fixedPostVars
Move thetx_news_pi1[action]entry to come aftertx_news_pi1[news]in your RealURL config. By processing the news slug first, TYPO3 infers the correct action automatically, so the action parameter doesn't create an empty segment—eliminating the double slash. - Option 2: Remove the
tx_news_pi1[action]config
If your site doesn't require showing the action (like "detail") in the URL (which is the standard setup for tx_news), deleting this line entirely removes the empty placeholder that was causing the double slash issue.
内容的提问来源于stack exchange,提问作者josias

