Redirect shows alert X_OCTOBER_REDIRECT and is not working

Hi guys, I have a weird problem.
I wrote a simple contact form (example url: /contact/form ) and I want to redirect the user to a thank you page after the submit.
The issue is that it doesn’t redirect the user but shows an alert showing the following message

{"X_OCTOBER_REDIRECT":"https:\/\/my-website.com\/contact\/thank-you-page"}

I tried to debug and i found the following behaviours while changing the form url:

  • /contac/form - Removing the last char from “contact” in the url path IT WORKS!
  • /contact/form - The desired url (with the final ‘t’ in ‘contact’ ) doesn’t work
  • /contacts/form - Adding another char to ‘contact’, it doesn’t work.

I suppose there is some url conflicts but I checked every page and there are no pages that can conflict with it.

Here a little of my code:


contact/form.htm

{{ form_ajax('onSubmitForm')  }}

<div class="row">
	<div class="col-md-6 mb-1">
       <input type="text" class="form-control" name="name" placeholder="Name *" required />
	</div>
        <!-- ... other fields like above (surname, email, subject, text) -->

        <!-- Submit button -->
	<div class="col-md-6 mt-4 text-end">
		<button type="submit" id="btn-send-contact" class="btn btn-white">Send</button>
	</div>
</div>
{{ form_close() }}

ContactForm.php

class ContactForm extends ComponentBase
{
    public function componentDetails()
    {
        //...
    }

    public function defineProperties()
    {
        return [
            //...
            'thankYouPage' => [
                'title' => 'Thank you page title',
                'description' => 'Thank you page description',
                'type' => 'dropdown',
                'default' => ''
            ]
        ];
    }


    public function getThankYouPageOptions()
    {
        return Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');
    }

    public function onSubmitForm()
    {

        $r = Request::all();

        // Field validation (works well)
        // ...

        // Email send (works well)
        // ...
        
       // Redirect to Thank you page - Doesn't work with desired URL
       return Redirect::to($this->pageUrl($this->property("thakYouPage")));

    }
}


I tried to rewrite the entire contact form page from scratch with another url (/test), including only my component first, then styles, them scripts, then other components, then including layout and making the page identical to the original contact form page: it always worked.
Then I tried to change the file name to the original contact form page file name: it worked.
Finally, changing the url makes the error appear.

Can anyone help me?

Hi, I found the issue.
There was a wrong redirect in the .htaccess file.

RewriteRule ^contact /contact/form [R=301]

There’s a missing $ at the end of “contact” and the rule redirects all the url that begins with “contact”, e.g.:

  • /contact
  • /contacts
  • /contact/form
  • /contact/than-you-page

The following url matches only /contact and is correct:

RewriteRule ^contact$ /contact/form [R=301]
1 Like

Hi, and welcome @serlo89!

Glad you got it sorted, without knowing about this .htaccess, it was indeed a confusing problem. Thanks for reporting back with the solution.