RouteEnhancer for TYPO3 v9 indexed_search - typo3

I want to rewrite the URL for search result from indexed_search but it's not working. Nothing happen.
I've added following RouteEnhancer to my config.yaml
routeEnhancers:
IndexedSearchPlugin:
type: Extbase
limitToPages:
- 38
extension: IndexedSearch
plugin: Pi2
routes:
- routePath: '/page/{page}'
_controller: 'Search::search'
_arguments:
page: '#widget_0/currentPage'
defaultController: 'Search::search'
defaults:
page: '0'
requirements:
page: \d+
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
Maybe somebody have an idea?

I don't use index_search a lot, but had a quick look at the code for the page browser. The page browser for indexed_search is done using a form and JavaScript, not direct links. So when clicking on a page in the page browser a hidden field is set and the form is submitted. Route enhancers will only work for links generated by TYPO3. I'm not sure why this is done this way, but without changing the way the page browser works you can't enhance these URLs.

I guess it depends on what you are trying to beautify. In my case I use this config.yaml to get a clean url for the search results (the search field is generated by TypoScript) and be able to search by a query.
Let's say we're having a page https:example.de/search/ with the indexed_search plugin placed on it.
Now searching from any page with the search field will result in this uri:
https:example.de/search/results
And you can deeplink to a special search result (here we're looking for 'lorem') by simply using that uri:
https:example.de/search/query/lorem
routeEnhancers:
IndexedSearchPlugin:
type: Extbase
namespace: tx_indexedsearch_pi2
routes:
- routePath: '/results'
_controller: 'Search::search'
_action: 'search::search'
- routePath: '/query/{search/sword}'
_controller: 'Search::search'
_action: 'search::search'
requirements:
- search/sword: '[^/=?]*'
defaultController: 'Search::search'
defaultAction: 'search::search'
At least this did work for me in TYPO3 v10.4.8 (without testing pagination or advanced search).

Rudy Gnodde is right: There is no 'page' parameter, so you don't need to configure it.
Just use following routeEnhancer to have an URL like www.domain.com/my-search-page/search where my-search-page is the page holding the indexed_search plugin.
routeEnhancers:
IndexedSearchPlugin:
type: Extbase
extension: IndexedSearch
plugin: Pi2
routes:
- routePath: '/search'
_controller: 'Search::search'
defaultController: 'Search::search'

Related

TYPO3 v9 and up: How to enable disabled TYPO3 site language redirect without trailing slash

Problem
If you disable a site language of a configured TYPO3 site a redirect is automatically done to the "default" language.
I have configured two languages in my scenario (shortened site config example):
base: 'https://www.alrightsantleit.com/'
languages:
-
title: English
enabled: true
languageId: '0'
base: /en/
typo3Language: default
-
title: Deutsch
enabled: false
base: /de/
typo3Language: de
locale: de_DE.utf8
fallbackType: strict
fallbacks: ''
languageId: '1'
Redirect Check
curl -I https://www.alrightsantleit.com/de fails and leads into error 503
curl -I https://www.alrightsantleit.com/de/ succeeds and lead to status 301 with correct redirect to https://www.alrightsantleit.com/en/
How to fix this problem?
From a technical perspective and the strict routing (since TYPO3 v9 and up) an additional redirect without trailing slash must be added manually.
But is this the right solution for such scenario?
Do I have to force trailing slashes in each request (e.g. by using composer package studiomitte/redirect2trailingslash) by hand?
Is this some missing "feature" of TYPO3 to respect also a configured base without a trailing slash?
Can it be completely ignored and do have internet people learn to add proper trailing slashes when typing urls or when editors of external sites links without trailing slash in their website?
How do you solve that in your project? And what's the correct way to make it error-proof?
A 503 and a 303 is wrong, we would need a 404 in each case. A "hidden" language is exactly like a hidden page = 404 does not exist.
We add two things to all our installations with TYPO3 v9 or higher:
In the site configuration we add the trailing slash:
routeEnhancers:
PageTypeSuffix:
type: PageType
default: /
index: ''
map:
/: 0
And with the .htaccess we enforce the trailing slash for every request:
RewriteRule ^([^\.]*[^/])$ https://%{HTTP_HOST}/$1/ [L,R=301]
With that our URLs always have the trailing slash.

Configure static route for form submit action in TYPO3 9.5.5

I have an Extbase extension which renders the form in the frontend and my URL is as below:
https://domain.ch/de/news/add/?tx_newsform%5Baction%5D=new&tx_newsform%5Bcontroller%5D=News&cHash=041eab0915b1445827046afef933eb26
I need a static route for the submit action. I have added below YAML configuration.
routeEnhancers:
NewsFormPlugin:
type: Extbase
extension: NetcNewsform
plugin: netcnewsform
routes:
- { routePath: '/new-article/success', _controller: 'News::create'}
defaultController: 'News::new'
requirements:
page: '\d+'
This shows perfect static route in the form action, but while I submit the form this won't show the same URL in the browser.
Can anyone guide me? Big thanks!
I have fixed the issue, I had made a minor mistake which causes the issue. My action redirects to the New action of the controller and I had passed the wrong action at the YAML configuration.
routeEnhancers:
NewsFormPlugin:
type: Extbase
extension: NetcNewsform
plugin: netcnewsform
routes:
- { routePath: '/new-article/success', _controller: 'News::create'} # Here is the issue
defaultController: 'News::new'
requirements:
page: '\d+'
Instead of the above configuration, I used the below configuration.
NewsFormPlugin:
type: Extbase
extension: NetcNewsform
plugin: netcnewsform
routes:
- { routePath: '/new-article/success', _controller: 'News::create'}
- { routePath: '/new-article/success', _controller: 'News::new'}
defaultController: 'News::new'
requirements:
page: '\d+'
One more thing, I have added routes for create and new action both.
This working pretty well!

Real URL's in Typo3 9.5.0

How can I get URL's like
expample.com/home.html
in Typo3 950? Typo3 creates only URL's like
expample.com/home
without .html.
You can define the default page type by adding a route enhancer in your routing site configuration config.yaml.
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '.html'
map:
'.html': 0
See also here https://docs.typo3.org/typo3cms/extensions/core/Changelog/9.5/Feature-86160-PageTypeEnhancerForMappingTypeParameter.html
More about config.yaml file see https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/SiteHandling/Basics.html
Add this code to config.yaml:
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '.html'
map:
'.html': 0
Then add a redirect in sitemanagement from index.html to example.com

As 'host' is deprecated for manifest.yml - how to configure a standard scapp.io route?

CF CLI now warns with a deprecation message:
Deprecation warning: Route component attributes 'domain', 'domains', 'host', 'hosts' and 'no-hostname' are deprecated. Found: host.
My manifest.yml looks like that currently:
applications:
- host: myexample-test
which results in a final route like: myexample-test.scapp.io
how to define this exact same route with the new manifest routes config?
These examples are taken from the cloudfoundry docs but I am not sure whether swisscomdev is adopting anything behind the scenes?
routes:
- route: example.com
- route: www.example.com/foo
- route: tcp-example.com:1234
UPDATE
Just tried it with suggested solution and this manifest:
applications:
routes:
- route: myexample-test.scapp.io
name: MyExample
buildpack: nodejs_buildpack
instances: 1
memory: 64M
which resulted in the following error message:
yaml: unmarshal errors:
line 2: cannot unmarshal !!map into []manifest.Application
Swisscom Application cloud does not do something special behind the scenes, so you can apply what's written in the CF CLI docs.
If we're doing something other than vanilla CF, we will mention this in our docs.
I quickly checked it, the following does the trick for your route:
routes:
- route: myexample-test.scapp.io
In your example, note that applications must be an array of maps, so make sure the first element key contains a -, otherwise it's treated as a map.
Full example:
applications:
- name: MyExample
routes:
- route: myexample-test.scapp.io
buildpack: nodejs_buildpack
instances: 1
memory: 64M

Symfony2 - multiple page login form in modal window

I have this modal window with login form and I am displaying it in multiple page. The problem is that my login form is working only in homepage. It is because I described so in security.yml:
secured_area:
pattern: ^/
anonymous: ~
provider: main
form_login:
login_path: /
check_path: /
default_target_path: /authorization
logout:
path: /logout
target: homepage
remember_me:
secret: '%secret%'
lifetime: 31536000
Do I have to create multiple areas like this one for each page even though it is using exactly same login form in modal window?
For example:
contacts_area:
pattern: ^/contacts
anonymous: ~
form_login:
login_path: /contacts
check_path: /contacts
default_target_path: /authorization
about_area:
pattern: ^/about
anonymous: ~
form_login:
login_path: /about
check_path: /about
default_target_path: /authorization
// and so on
Any ideas how overcome this ugly solution? Is it possible?
In the end after some research I found out that it is impossible to have it done other way. I modified my areas and they are working better than ever:
about:
pattern: ^/about
anonymous: ~
provider: main
context: primary_auth
form_login:
login_path: /about
check_path: /about/login_check
default_target_path: /authorization
remember_me:
secret: '%secret%'
lifetime: 31536000
I modified check pathes so I could have more forms in same page. Apparently I had submit problems from oter forms in same page as login form. Changing check_path fixed the problem.