Skip to main content
11 votes

How to redirect from plugin?

In Craft 3 we are looking at something similar to: Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('settings/plugins/craft-mailchimp'))->send();
Clark Nelson's user avatar
8 votes
Accepted

{% redirect "{{ entry.url }}" %} doesn't work

You do not use the {{ }} inside other brackets you also should not use ' ' unless it is a specific string you want interpreted. Try instead: {% for entry in craft.entries.section('services').limit(1) ...
Christopher Healey's user avatar
7 votes

How do I redirect traffic from a legacy category URL to a new category URL?

There are a few plugins which can handle this, but Retour is the newest and shiniest! https://github.com/nystudio107/retour It's from the same developer as SEOmatic... he puts a lot of love & ...
Lindsey D's user avatar
  • 24k
6 votes
Accepted

How do I redirect traffic from a legacy category URL to a new category URL?

Craft has a twig redirect tag. You should be able to create a "redirect" template that handles redirects based on {slug} and/or url segments and then use Craft routes to direct "legacy-subdirectory"...
Moto_Nomad's user avatar
6 votes
Accepted

how can pass a variable in redirect?

I think: {% redirect "/visit/index?artwork="~workTitle %}
AbbeyDesign's user avatar
  • 1,527
5 votes

how can pass a variable in redirect?

Update line 5 to concatenate the path/URL with the variable workTitle. {% redirect "/visit/index?artwork=" ~ workTitle %}
Selvin Ortiz's user avatar
  • 1,623
5 votes
Accepted

Anyone with a tricked out .htaccess file

Been using this one for years, works great: <IfModule mod_rewrite.c> RewriteEngine On # ========================================= # # Force website to use "www" RewriteCond %{...
Lindsey D's user avatar
  • 24k
5 votes
Accepted

/login page in Craft keeps redirecting to home page. What could be causing that?

/login is the default login page for Craft (see https://craftcms.com/docs/config-settings and scroll down to the users section ). You can override it by adding something like this to your config file: ...
Roi Agneta's user avatar
  • 1,463
4 votes

Redirects are Overriding each other

Try swapping the order of your Routes (drag and drop), so that specific resources are routed first and the homepage fallback is positioned second. Routes are applied in the order the appear in ...
Matt P's user avatar
  • 1,548
4 votes

Charge plugin redirecting to page with "1" on it

I'm the developer of Charge. I've never directly observed that behaviour, but it sounds like it's most likely hitting a redirect failure and falling back to some base success/fail responses. The ...
Joel Bradbury's user avatar
4 votes
Accepted

Redirect entry type to another domain

The reason that you get that odd URL with the {% redirect %} tag is just because there's some whitespace at the beginning of the value returned from your helpers.msuLink() macro. Using the |trim ...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

provide a 'back' or 'cancel' or 'close' button to return to whatever page that particular template was accessed from

You could use the Cookies plugin to store the last visited URL before the user hits one of the "step" templates, i.e. by putting something like the following in every template where the links to the "...
Mats Mikkel Rummelhoff's user avatar
4 votes

Trailing slashes with Nginx and Craft

After some digging, there appear to be two ways that avoid hitting the admin and url query strings. The first, (and apparently better one, as 'if is evil' according to nginx) uses location handlers: ...
hisnameisjimmy's user avatar
4 votes

Trailing slashes with Nginx and Craft

Nginx-Craft has an example setup that does this: https://github.com/nystudio107/nginx-craft/blob/master/sites-available/somedomain.com.conf#L60 # 301 Redirect URLs with trailing /'s as per https://...
andrew.welch's user avatar
  • 11.6k
4 votes
Accepted

How to show homepage for 404 errors

404 isn’t a valid redirect status code, which is why {% redirect '/' 404 %} isn’t working correctly. It sounds like you want to: first issue a 301 or 302 redirect to the homepage then serve the ...
Brandon Kelly's user avatar
4 votes

Craft 3 redirect of existing and non-existing URLs

Based on your comments, I'd recommend creating a new entry type in your section. Create a "Redirect" entry type which only contains a URL link (or an Entry field) so the page knows how to handle the ...
Lindsey D's user avatar
  • 24k
4 votes
Accepted

Redirect all but certain requests to index

This will redirect all queries but urls containing: api or robots or utm_source strings return array( '^(?!.*(api|robots|utm_source)).*$' => ['template' => 'index'] );
HendrikEng's user avatar
  • 1,064
3 votes
Accepted

Redirecting "if entry is not defined" returns 404 instead

The reason you're getting a 404 is because Craft isn't even hitting your help/_entry.html template. Because there's no entry matching the URI /help/asdf, the template will never render and the request ...
Mats Mikkel Rummelhoff's user avatar
3 votes

Controller action redirection when called via route

In case you need this for CraftCMS version 3, as I did today, the code slightly changed: $this->redirect(Craft::$app->getRequest()->referrer); This works fine with version 3.
Luke's user avatar
  • 531
3 votes

Migrate WordPress Site into Craft CMS. How deal with 404's?

David, I like using Reroute. It's a Craft plugin that lets you create 301s and 302s to any of your entry pages within Craft.
Tim Knight's user avatar
  • 1,022
3 votes
Accepted

Possible to redirect elsewhere after saving an entry?

Yes! Assuming you're using some sort of business logic plugin (if you don't have one, get one), then simply put this code in your main *Plugin.php file... public function init() { // Trigger ...
Lindsey D's user avatar
  • 24k
3 votes
Accepted

Redirect to another EntryType template if no Children exist

Fixed! So bearing in mind i'm using this method to load templates according to entry type, Clive Portman's answer got me thinking about hasDescendants. In my _entry.html I now have something like ...
Martin's user avatar
  • 1,203
3 votes

Redirect Manager 301 results in "Entry DNE" error

Turns out that I was right on the money with my plugin configurations, however earlier I had incorrectly tried to solve the problem using the route below, which was still in place and scuppering my ...
Andy Westmoreland's user avatar
3 votes

Anyone with a tricked out .htaccess file

Since you mentioned in an earlier post that you are performance-minded, this might interest you: Stop using .htaccess files! No, really.
andrew.welch's user avatar
  • 11.6k
3 votes

provide a 'back' or 'cancel' or 'close' button to return to whatever page that particular template was accessed from

If you need to set a correct link on the cancel buttons than using browser history is the easiest way. {% if entry is defined %} // Going to STEP2 <button onclick="window.history.go(-1); ...
Dominik Krulak's user avatar
3 votes
Accepted

How do I redirect from a legacy category URL to a new catgory URL using Retour

Despite having used regex's for years, I still almost never get them right from memory. A great tool for testing them out is: https://regexr.com/ What you'll need to use is a capture group. Something ...
andrew.welch's user avatar
  • 11.6k
3 votes

Is there a way to get the previous page URL to the current referring page?

You can get the previous page (within the same site) with {{ craft.app.request.referrer }}.
Oli's user avatar
  • 7,495
3 votes

Is it possible to create non-existent parent page in Craft?

You do not need the parent page. If I understand it correctly: Create a section for your content named dogs. It could be a structure or channel (depends if you need it hierarchically or ...
Thomas Sausen's user avatar
2 votes

Localized Site -> howto redirect Browser

I recently released Country Redirect, a plugin that handles this smoothly: https://superbig.co/plugins/country-redirect It lets you map which countries get redirected to which locales, let visitors ...
Fred Carlsen's user avatar
  • 2,997
2 votes

Password protect whole staging site. Redirect to original page not working

{% requireLogin %} is intended for use with your own login form on the frontend rather than the standard /admin one. From the docs for loginPath: The URI Craft should use for user login on the ...
Clive Portman's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible