0

I wanted to eliminate duplicate content by redirecting all requests to https://www... by using the below .htaccess entry:

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#

## Force https and www
#RewriteCond %{HTTPS} off [OR]
#RewriteCond %{HTTP_HOST} !^www\.gonativeguide\.com$ [NC]
#RewriteRule ^(.*)$ https://www.gonativeguide.com/$1 [L,R=301]

## Remove trailing slash if not directory
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} (.+)/$
#RewriteRule ^(.*)/$ https://www.gonativeguide.com/$1 [R=301,L]

## End - Custom redirects  

Adding this entry seem to do the job for the redirect, however it blocks my users to log into my site using email links. When the user needs to log in she gets a notification email with a button that links to the below address: https://www.gonativeguide.com/de/backoffice/markavail?inquiry=437

Joomla changes the above link to the below one, asking the user to log in: https://www.gonativeguide.com/de/component/users?view=login&Itemid=214

Previously this worked perfectly fine. But with the .htaccess entry, my users get the below error message:

Warnung Der Sicherheitstoken ist falsch. Die Anfrage wurde zurückgewiesen, um eine Sicherheitsverletzung zu verhindern. Bitte die Seite aktualisieren und erneut versuchen.

I believe this is equivalent to:

The most recent request was denied because it contained an invalid security token. Please refresh the page and try again.

I think I could find a workaround to the problem: If I log in by typing www.gonativeguide.com/login and THEN click the link in the email, then it seems to be working. However it is super embarrassing to ask my users to do so all the time, so I'd like to find a solution to the problem.

I read through the related (lengthy) forums talking about the invalid security token problem and tried the below suggestions, but none helped:

  • Flush cache at the host
  • Flush cache in Joomla
  • Checking if the System - Page cache plugin is disabled (it was disabled)
  • Empty the _session table in the Joomla database
  • Upgrading Joomla to the latest version
  • Fixing the database (Extensions / Manage / Database)
  • Extending the session timeout to 10 hours

Can somebody explain to me, why the .htaccess entry causes this problem, and how can I do the redirect without this side effect?

5
  • Can you perhaps rewrite this and possibly rollback your previous question's edit so that this page refers to that question but isn't so redundant with its details? I would like researchers to be able to easily differentiate between these two recent questions of yours. – mickmackusa Aug 1 '20 at 9:10
  • I'm not 100% sure about all this, but one possibility might be if she was previously using the domain gonativeguide.com (without the www). Afaik the token is associated with the session, and the session with the cookie, and the cookie is particular to the domain, so if the previous token was associated via the session with gonativeguide.com domain and then she was redirected to www.gonativeguide.com, then that would mean a different cookie & session and hence a different token. You could try using mod_rewrite LogLevel to see what rewrites are actually being done. – Robbie Jackson Aug 2 '20 at 21:04
  • Thanks for the hint. I can reproduce this problem with my test user as well. How could I check that this was really the problem? What would be a good test? Thanks! – wanderlusted Aug 3 '20 at 13:16
  • See httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging for using LogLevel. This will output to your apache log file the rewrites that it performs (based on the logging level) - but will be for every http request coming in, so could generate a lot of data and slow the web server down. Or if you have a test user then it would be better to just put the browser devtools on and look at the Network tab to see redirects - to see if it is going from gonativeguide.com to www.gonativeguide.com - to see what effect your htaccess directives are having. – Robbie Jackson Aug 3 '20 at 20:55
  • Thanks again for the hint. After removing the second part of the redirect (## Remove trailing slash if not directory) the problem went away. I still don't understand why this was causing a problem, but finally my problem is solved. Thanks! – wanderlusted Aug 10 '20 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.