Redirect user to mobile site and back in typo3 with typoscript - typo3

I have found that if I use the below typoscript I can redirect my users to the mobile version of the site which has its own tree in the backend of my typo3 site.
[useragent = *iPhone*]||[useragent = *iPod*]||[useragent = *Android*]
config.additionalHeaders = Location: http://m.example.com/
[end]
It is a simplified version of the site however so I want to have a return to full website link. But due to my above typoscript redirecting users to the m domain i can't get back to www.example.com.
Does anyone have any typoscript suggestions here?

You need an additional parameter in your link back which you can use to turn off the redirection.
Try something like this:
# check for mobile browser
[useragent = *iPhone*]||[useragent = *iPod*]||[useragent = *Android*]
config.additionalHeaders = Location: http://m.example.com/
[global]
# undo mobile redirect if mobile param is set
[globalVar = GP:nomobileredirect > 0]
config.additionalHeaders =
[global]
and redirect to http://www.example.com/?nomobileredirect=1 on your link back.
To keep a nomobileredirect-value in all generated links, add nomobileredirect to your linkVars, e.g.
config.linkVars = nomobileredirect,L

You can use another condition on a GET parameter and override the config.additionalHeaders later. Remember, TS is not a scripting language, but rather a static configuration. The last statement always wins and rendering starts only once all TS has been parsed.
You can also try to extend the above condition by an additional exclude of a GET parameter.

Related

Dynamic Links from a CMS - Error: "redirect" can not be returned from getStaticProps during prerendering

I have a Next JS app connected to a CMS and hosted on Vercel - all links are dynamic and the pages are created by the content authors.
I am trying to create dynamic redirects that will force URLs to adhere to formats that are better for SEO. For example:
Enforce lowercase URLs
Replace spaces with dashes
Remove trailing slashes
For example, /test/Author Name/ would redirect to /test/author-name
Since I need to trigger a 301 redirect for these wrong URLs, the only way to do this with Next JS from what I have found is to return a Redirect from getStaticProps, this is what I have so far:
export const getStaticProps: GetStaticProps = async (context) => {
let requestedUrl = '/';
if (context?.params?.path) {
requestedUrl = '/' + (context?.params?.path as string[]).join('/');
}
//check for URLs with uppercases, spaces, etc. and clean them up
let modifiedUrl = requestedUrl;
modifiedUrl = modifiedUrl.trim().toLowerCase().replace(/\s\s+/g, ' ').replace(/\s/g, '-');
if (modifiedUrl != requestedUrl) {
return {
redirect: {
destination: modifiedUrl,
permanent: true,
},
};
}
This works wonderfully well running locally and connected to the CMS - everything is working as it should and all "faulty" URLs are corrected with the correct response code.
Sadly, this does not work on build, I have spent so much time so far trying to find an alternative, but no matter what I do, the build on Vercel fails with the error:
"redirect" can not be returned from getStaticProps during prerendering
The next best potential solution is to use Middleware, but that requires v.12 at least. Due to limitations from the CMS connector, we are forced to use Node v.11 :(
The alternative that I have built is to use router.push on the client side, but this... just looks terrible. The page loads, returns a 200, and then loads again with the corrected URL. Not good for the user's experience.
Any advice or suggestions? I am baffled that something this simple is this complicated with Next JS!
I resolved the issue... it looks like redirects on statically generated pages are not possible unfortunately. I removed getStaticProps and getStaticPaths, and added getServerSideProps instead. The redirects are now working correctly, but the site is not as fast as we are losing out on SSG.

TYPO3 10: Disable page when not logged into backend

In TYPO3 10 is there a way to disable a page for anyone not logged in to the backend. Prior to Typo3 10, I believe something like this worked:
[getTSFE() && getTSFE().isBackendUserLoggedIn() == false]
page = PAGE
page.10 = TEXT
page.10.value = Page disabled
[GLOBAL]
But in Typo3 10 this does not work any more because of changes in the TSFE Array.
Since 9.5.16/10.4.1, you could use [backend.user.isLoggedIn] or [backend.user.isAdmin] (TSref) for checking BE user properties.
Maybe it would be a better approach to "hide" the page for unwanted visitors by setting an HTTP auth...
Update:
Tested both variants. Both condition variants are matching in an TYPO3 v10.4.17/10.4.19:
page.200 = TEXT
[getTSFE() && getTSFE().isBackendUserLoggedIn() == true]
page.200.value = BE-User is logged in.
[getTSFE() && getTSFE().isBackendUserLoggedIn() == false]
page.200.value = BE-User is NOT logged in.
[global]
page.250 = TEXT
page.250.value = <hr />
page.300 = TEXT
page.300.value = BE-User is NOT logged in.
[backend.user.isLoggedIn]
page.300.value = BE-User is logged in.
[global]
Notice:
To get this work, your FE and BE must be able to share their session cookie. This means, both must be called with same domain (or appropriately configured cookie domain). Be aware with multi-domain instance and the variants with/without "www" (www.example.com != example.com)

TYPO3 Redirect to pid if user is logged in

The given scenario is a login page and another page with a user restriction.
What is the best practice to redirect the user automatically to the restricted page if he calls the login page but is already logged in?
The workflow should be:
User calls Login-page
TYPO3 detects that the user is already logged in
TYPO3 redirects the user to Restricted-page
Many thanks
Take a look at this extension : https://bitbucket.org/ideativedigital/t3-redirect40x/src/master/. I know it works with TYPO3 9 but you will probably need some adjustements if you need it to work with TYPO3 8.
In Typoscript you can use conditions to a) check if a user is logged in and b) check what page they are on. Then you can add some addtional headers to do the forwarding.
[usergroup = *] && [globalVar = TSFE:id = YOUR-LOGIN-ID]
config.additionalHeaders.cObject = COA
config.additionalHeaders.cObject {
10 = TEXT
10.value = HTTP/1.0 302 Temporary Redirect | Location: http://www.your-domain.com
20 = TEXT
20 {
typolink.parameter = YOUR-FORWARDING-ID
typolink.returnLast = url
}
}
[global]
usergroup can be * = all usergroups or you can put the actual ID of the usergroup(s) you want to forward. YOUR-LOGIN-ID should be the pid of the page where your login is. YOUR-FORWARDING-ID should be the id of the page you want to forward to

How to delete facebook parameters that puts the url's shared on your wall in codeigniter links

When I share a link http://www.totalrunning.com/results/misFotos/TTRCAR1346364033/283 (Codeigniter Url's) on my Facebook wall appears fine but when clicking the resulting URL is: http://www.totalrunning.com/results/misFotos/TTRCAR1346364033/283?fb_action_ids=441641579216005&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582
fb_action_ids added among other parameters this causes the url not resolving correctly
That I can do to make facebook not put those parameters in my url or like handling with Codeigniter ???
Thanks
Enabling Query Strings
In some cases you might prefer to use query strings URLs:
index.php?c=products&m=view&id=345
CodeIgniter optionally supports this capability, which can be enabled in your application/config.php file. If you open your config file you'll see these items:
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
If you change enable_query_strings to TRUE this feature will become active. Your controllers and functions will then be accessible using the "trigger" words you've set to invoke your controllers and methods:
index.php?c=controller&m=method
You can read more at the Code Ignitor user-guide here: http://codeigniter.com/user_guide/general/urls.html
The solution I found was through the same file using Codeigniter .htaccess to hide the index.php
Above this htaccess put the following:
# -----------------
RewriteCond% {QUERY_STRING} ^ fb_action_ids = (. *) $ [NC]
RewriteRule ^ (. *) $ / $ 1? [R = 301, L]
# -----------------
with this code you tell the server that elime the query string of the url but only when he comes fb_action_ids or any parameter you choose not prevent the proper functioning of query strings in CodeIgniter
With this you can preserves the beautiful codeigniter urls and facebook links resolved correctly!
Important: Put it up to avoid file overwrite functionality to hide the index.php
I wouldn't recommend this method. Just add a slash after your final parameter and it will work fine. It will ignore all those facebook extras

Codeigniter - How to get and change uri segement then redirect?

In my web application I have a url that looks like the following:
http://mydomain.com/search/index/list/for-sale/london/0/0/0/0
I would like to use the uri class and redirect to change $this->uri->segment(3); to map and then redirect.
So that once redirected and the segment has been changed the url would look like:
/search/index/map/for-sale/london/0/0/0/0
How would I go about doing this?
It may need some extra checks, but this would be a simple approach:
$segment_to_replace = "/".$this->uri->segment(3)."/";
$new_url = str_replace ($segment_to_replace, "/map/", current_url());
redirect ($new_url);