20 votes
Accepted

301 Redirects Appends ?p=original/url/path - how can I remove?

The issue here is that your Redirect directive is conflicting with Craft’s index.php-hiding RewriteRule directive. (Redirect is a mod_alias directive and RewriteRule is a mod_rewrite directive. They’...
user avatar
  • 2,455
14 votes
Accepted

How to redirect from plugin?

You can use the HttpRequestService: craft()->request->redirect($myAwesomeUrl);
user avatar
13 votes
Accepted

How to redirect to Coming Soon template

If you are trying to cover the site from the public while working on it live, i personally would name my coming soon template file 503.html Then in the General Settings section of the control panel, ...
user avatar
  • 496
11 votes
Accepted

Login redirects to home page after 2.2 update

As Brad said the new default behavior is for users to be redirected wherever postLoginRedirect is set to (if a redirect param was not in the POST data). You can get your old behavior back by adding ...
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</...
user avatar
10 votes
Accepted

How to automatically redirect a url based on dynamic content

Take a look at Craft's redirect function: {% redirect '/' %} In your case it would look like this: {% redirect 'neptune/' ~ id ~ '/confirm' %}
user avatar
  • 8,326
9 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();
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 ...
user avatar
  • 6,477
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) ...
user avatar
7 votes
Accepted

How to redirect if entry has children?

You have twig syntax ({{...}}) inside twig syntax ({%...%}), which is never right. Does this work? {% if entry.hasDescendants() %} {% redirect entry.getChildren().first().url %} {% endif %}
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 & ...
user avatar
  • 23.6k
6 votes

301 Redirects Appends ?p=original/url/path - how can I remove?

One way you can avoid this is by making a small change to the htaccess rules for removing index.php from Craft URLs. You can remove the query string from RewriteRule (.+) index.php?p=$1 [QSA,L] and ...
user avatar
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"...
user avatar
6 votes
Accepted

how can pass a variable in redirect?

I think: {% redirect "/visit/index?artwork="~workTitle %}
user avatar
  • 1,517
5 votes
Accepted

htaccess www to non-www redirect (and config.php)

Providing you have the necessary permissions to do this, the following in your .htaccess should do the job: RewriteCond %{HTTP_HOST} !^domain\.co\.uk$ [NC] RewriteRule ^(.*)$ http://domain.co.uk/$1 [...
user avatar
5 votes

Localized Site -> howto redirect Browser

Here is what i have done. Not sure if it helps you. I can't add comments. So here you go. This is based on geo plugin Plugin serviceclass: //to get local ele private function getLocalElement() { ...
user avatar
  • 83
5 votes
Accepted

Get the ID of a new entry when it's saved

If you wanted to do this without having to write your own plugin, you can achieve this with a simple custom route and an extra parameter in your template. Your hidden fields could look like: <...
user avatar
  • 4,519
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 %}
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 %{...
user avatar
  • 23.6k
4 votes

Login redirects to home page after 2.2 update

Craft 2.2 introduced the postLoginRedirect config setting which affects not only where users on the front-end of the site get redirected to after logging in (defaults to the home page), but where they ...
user avatar
  • 66.5k
4 votes

Setting up redirects via Craft routes?

If you want to "redirect" all parent entries of your structure that have child entries, you could do something like this in your navigation (untested code!): <ul> {% nav page in pages %} ...
user avatar
  • 35.9k
4 votes

Redirect IE7 or below users to a new page

I agree with Bryan, personally I like to use the Browser-Update.org notification. Nevertheless, if you want to use .htaccess just make sure you put your redirect code before Crafts routing: <...
user avatar
  • 8,326
4 votes

How do I force a 301 http status code using the redirect tag?

Although it is (as of today) not yet documented, looking through the redirect twig extension revealed that the redirect tag can accept a second parameter for the http status code. So forcing a 301 is ...
user avatar
  • 6,326
4 votes
Accepted

What's the most efficient way to handle a redirect of the home page?

.htaccess should always be faster because it doesn't involve PHP or Craft at all. But on top of that the {% redirect %} tag should be pretty darn quick. Upon hitting it, Craft immediately calls Yii'...
user avatar
  • 66.5k
4 votes

302 redirects to locales in main index.php

I would suggest making the “admin” check a little more strict: // Make sure this isn't a CP request if (!isset($_GET['p']) || strncmp($_GET['p'], 'admin', 5) !== 0) { // ... (Assuming you’re ...
user avatar
4 votes
Accepted

How to Redirect After Successful Registration Confirmation

The config settings you're looking for are probably 'activateAccountSuccessPath' and 'autoLoginAfterAccountActivation'.
user avatar
  • 66.5k
4 votes

How to redirect to Coming Soon template

You can use the redirect tag. Put this in your index.html template: {% redirect "coming-soon" %} EDIT If you want to stay on the homepage but want to show the template code for another page, you ...
user avatar
  • 3,604
4 votes

Force trailing slash on URLs

I found by just adding the code from the following site it will add slashes via a 301 redirect: RewriteCond %{REQUEST_URI} /+[^\.]+$ RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L] Now my .htaccess ...
user avatar
  • 1,355
4 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,...
user avatar
  • 141
4 votes
Accepted

Redirects or Routing for Landing Page URL's?

You can either set the URL Format of the landing pages channel to {slug} (the same as your normal pages) Or you could try putting the landing pages in the normal pages structure, but give them a new ...
user avatar
  • 566

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