-->

TYPO3: 404 for restricted access page instead of l

2019-01-17 23:50发布

问题:

I have a link pointing to restricted page. When I access the link directly in logout status, its redirect to 404. Actually it should redirect to login form.

I tried:

config {
   typolinkLinkAccessRestrictedPages=PAGE_ID 
   typolinkLinkAccessRestrictedPages_addParams = &return_url=###RETURN_URL###&pageId=###PAGE_ID###
   }

Not working.

Also I tried the login status redirect plugin, no use.

Anyone know how to do this? I am using TYPO3 version 4.4.8.

回答1:

As this is still unanswered, does this help?

# Check if user is logged in:
[usergroup = *]
# do something
[else]
page.config >
page.config.additionalHeaders = Location: http://www.yourdomain.org/login.html
[end]

I recently posted this to another questions and it crossed my mind that it might be a suitable workaround for your probem.

Found here



回答2:

I'm not sure how to make redirection work correctly, but perhaps a bit of background will be helpful.

typolinkLinkAccessRestrictedPages only interacts with link generation. That way, anywhere you have a link to an access restricted page, you should get a link that points to the "PAGE Id" page. I suspect you are using your login pid in place of PAGE Id, which I guess should work, but I haven't used this particular feature. I have typolinkLinkAccessRestrictedPages = NONE which makes all links show up, linked to the correct url, but only users who are logged in will successfully load those pages.

If anyone, without being logged in, uses a bookmark to an access restricted page, or they click on one of these links, or directly type in the address, or whatever, they will run into TYPO3's 404 handling (with the error message: ID was not an accessible page). To change how TYPO3 handles these errors, you need to change what TYPO3 does via this setting in localconf.php:

$TYPO3_CONF_VARS["FE"]["pageNotFound_handling"]

I don't know if there's a clean way to just automatically redirect to the login page without hacking the pageNotFound_handling.

As far as the typoscript solution, that wouldn't work for my site, because the trigger isn't whether or not someone is logged in (often they will not be logged in)--the trigger for my site is trying to access a protected page when you are not logged in. I don't want it to redirect everyone who isn't logged in because a lot of pages don't require any login.



回答3:

Fe_login cannot alone do this...

Follow these steps::

  1. Install "pagenotfoundhandling" extention after felogin login configuration.
  2. Configure 403 page as login page in "pagenotfoundhandling" extention configuration.

Then, when you try to access "Access restricted page", "pagenotfoundhandling" will redirect to login page then pagenotfoundhandling handle redirect to again requested page. I have tested this on TYPO3 6.2.14



回答4:

And I found an other workaround that looks like it should work fine.

# pages and subpages starting at 123 and 321 are restricted
[PIDinRootline = 123,321] && [loginUser = ]
    page.headerData.666 = TEXT
    page.headerData.666 {
        data = getIndpEnv:TYPO3_REQUEST_URL
        wrap = <meta http-equiv="refresh" content="0; URL=/passwort/?referer= | " />
    }
[global]

Important notice: Do not restrict the complete page, only all contents of the page. Otherwise RealURL will trigger the 404 handler.

At the moment page.config.additionalHeaders (like used by @Mateng) does not support stdWrap, though you cannot add a referrer to redirect to the desired page after login (see TYPO3 Forge and vote for feature request).



回答5:

Complete solution : 1. first in typo3conf/LocalConfiguration.php you have to add:

'FE' => [
        'pageNotFound_handling' => 'REDIRECT:/login/',
        "pageNotFound_handling_statheader" => 'HTTP/1.1 404 Not Found',
         ...
],
  1. then add to typoscript :

    '

    config { typolinkLinkAccessRestrictedPages = YOUR_LOGIN_PAGE_ID typolinkLinkAccessRestrictedPages_addParams = &return_url=###RETURN_URL### } plugin.tx_felogin_pi1.redirectMode = referer

'



回答6:

Because there seems no proper solution for this behaviour of TYPO3, I use the following workaround with RealURL.

  1. Create a 404 page in TYPO3
  2. set the Speaking URL path segment to "404-error" and check Override the whole page path
  3. Add a text that describes what is happening (i. e. "Page doesn't exist or is restricted, please login")
  4. Add the felogin plugin to that page and hide it when users are logged in
  5. Set [FE][pageNotFound_handling] = /404-error/ in the install tool

This 404-error page is shown every time a user requests a page that he is either not allowed to see or a page that does not exist. When the user uses the login form on the page, he will find the proper content immediately after login because the URI did not change at all (when there is no redirect configured for the fe_login plugin).