TYPO3 news - Setting up URL and Title Tag
Steps for URL optimization of news (news)
What do we want to achieve?
- The URL of the single representation in the list should correspond to that of the title or an individual URL.
- Page browser should render the URL in the form of /page1/ ... /page2/.
- Select / Filter should output the category as a segment.
Parameters should be suppressed. - The title on the single view of the news should correspond to the headline or an individual title.
The Importance of a Good URL for SEO
A precise and clear URL is essential for search engine optimization (SEO). As an internet agency from Hanover, we aim to continuously optimize this. It serves as the first point of contact for search engines and users to understand the content of a webpage. A good URL should have the following characteristics:
Clarity and Relevance: A URL must clearly reflect the content of the page. Example: www.examplepage.com/seo-tips instead of www.examplepage.com/p12345.
Use of Keywords: Integrate relevant keywords to improve ranking in search engines.
Brevity and Conciseness: Shorter URLs are easier to read and remember. Avoid unnecessary words or characters.
Disadvantages of URLs with Parameters
URLs with many parameters are problematic for Google. They can have the following negative effects:
Complexity and Opacity: Parameters like ?id=123&cat=456 make it difficult to understand the page content and confuse users.
Duplicate Content: Search engines may interpret different URL variants as duplicate content, which deteriorates ranking.
Limited Readability: Users prefer simple URLs that are easily readable.
To avoid these pitfalls, one should pay attention to a clean URL structure that is optimized for both users and search engines.
How do I proceed with TYPO3?
The URL of the single display in the list should correspond to that of the title or an individual URL.
First, we open the file:
typo3conf/sites/main/config.yaml
Here, the TYPO3 site configuration is defined:
Under the standard definition, we can make further definitions:
routeEnhancers:
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
routes:
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments: {'news_title': 'news'}
- routePath: '/category/{category_title}'
_controller: 'News::list'
_arguments: {'category_title': 'category'}
defaultController: 'News::list'
aspects:
news_title:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_news'
routeFieldName: 'path_segment'
category_title:
type: PersistedAliasMapper
tableName: 'sys_category'
routeFieldName: 'slug' # Stelle sicher, dass deine Kategorien einen slug haben
aspects:
page:
type: StaticRangeMapper
range: [1, 2, 3, 4, 5] # Beispiel für Seitenzahlen
This configuration controls how the URLs for news articles and categories should appear in TYPO3. The code transforms technical URLs into beautiful, readable web addresses.
Purpose:
The code converts complicated system URLs into user-friendly URLs. For example, "index.php?id=123&news=456" becomes something like "/my-news-article" or, from a category view, "/category/sports".
Inputs:
News articles from the database (tx_news_domain_model_news)
Categories from the database (sys_category)
The original system URLs
Outputs:
User-friendly URLs for individual news articles (e.g., "/my-article")
User-friendly URLs for category overviews (e.g., "/category/sports")
How it works:
For individual news articles, the "path_segment" (a meaningful URL part) is taken from the database
For categories, the "slug" (also a meaningful URL part) is used
The configuration specifies which controller (News::detail or News::list) is responsible for which URL structure
The StaticRangeMapper at the end enables pagination from 1-5 for list views
Important Logic:
There are two main routes: one for individual articles and one for category views
Each route is assigned to a specific controller
The "aspects" ensure that the correct database fields are used for URL generation
The default view is the list representation (defaultController: 'News::list')
Display the News Detail View Title tag instead of the always the same title of the single page.
We, as an internet agency from Hannover, want TYPO3 to output the page title of the record/news for the user. For this, a TYPOscript needs to be added to the setup:
You can find one variant here:
[request.getQueryParams()['tx_news_pi1']['news'] > 0]
page.headerData.10 = CONTENT
page.headerData.10 {
table = tx_news_domain_model_news
select {
pidInList = root,-1
uidInList.data = GP:tx_news_pi1|news
languageField = sys_language_uid
}
renderObj = TEXT
renderObj {
field = title
wrap = <title>| - Schöpflin Schule</title>
}
}
[end]