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
11 votes
Accepted

Store a redirect URI for use after login

First – your Twig syntax is a little off. Here's how you could add the current URL/request path to a link, as a query parameter p: <a href="members/login?p={{ craft.request.path }}">Log in</...
Mats Mikkel Rummelhoff's user avatar
9 votes
Accepted

Why am I getting ?p=oldpage in a 301 redirect?

Craft works by taking requests that normally would 404—because they don't actually exist on the server but in the database. The piece that makes this happen is the rewrite rules. It's helpful to ...
RitterKnight's user avatar
  • 6,582
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
  • 23.9k
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

Force trailing slash on URLs

Craft has a config setting for this (for dynamic urls) You can set it in your config file like so: 'addTrailingSlashesToUrls' => true If someone links to the url via a non-trailing-slash pattern,...
Jbird's user avatar
  • 151
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
  • 23.9k
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,538
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

Controller action redirection when called via route

You're mistaken about how redirectToPostedUrl works... That's designed to redirect from a form submission, when the redirect field was supplied: <input type="hidden" name="redirect" value="page/to/...
Lindsey D's user avatar
  • 23.9k
4 votes
Accepted

Controlling where user is sent if clicking old or expired email activation link

It looks like the config setting activateAccountFailurePath is what you are looking for.
kcolls's user avatar
  • 608
4 votes
Accepted

On Entry Creation Redirect

You'd have to write a custom plugin, that adds an event listener for the entries.saveEntry event. The event listener should go into your plugin's primary class' init method. You'll need to make sure ...
Mats Mikkel Rummelhoff'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
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,413
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.4k
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
  • 23.9k
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

Changing the "homepage" url for logged-in users

Sure, something like this should work (untested): <a href="{{ currentUser ? url(craft.config.get('postLoginRedirect')) : siteUrl }}">Home</a> The above should create an absolute URL to ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

requireLogin not redirecting to login page

You should create your /login template with a custom login form. If you do that, the redirect should work as expected: craft.session.returnUrl is set to the original URL that included the {% ...
chris's user avatar
  • 906
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

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
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
  • 23.9k
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

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