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’...
14
votes
Accepted
How to redirect from plugin?
You can use the HttpRequestService:
craft()->request->redirect($myAwesomeUrl);
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, ...
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 ...
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</...
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' %}
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();
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 ...
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) ...
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 %}
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 & ...
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 ...
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"...
6
votes
Accepted
how can pass a variable in redirect?
I think:
{% redirect "/visit/index?artwork="~workTitle %}
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 [...
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()
{
...
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:
<...
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 %}
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 %{...
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 ...
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 %}
...
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:
<...
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 ...
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'...
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 ...
4
votes
Accepted
How to Redirect After Successful Registration Confirmation
The config settings you're looking for are probably 'activateAccountSuccessPath' and 'autoLoginAfterAccountActivation'.
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 ...
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 ...
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,...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
redirect × 131htaccess × 17
templating × 15
login × 15
redirection × 12
craft3 × 11
url × 11
control-panel × 7
form × 7
routes × 7
404 × 7
plugin-development × 6
entries × 6
https × 5
registration × 4
apache × 4
plugins × 3
localization × 3
entry × 3
config × 3
error × 3
routing × 3
variable × 3
password × 3
language × 3