Yeah. It’s possible to redirect with a plugin, a route, a controller, a template or a snippet. As long as it’s done before the html (or any output on the screen), it works.
In a route it would be like this for a single url:
I used your anti-pattern today. It’s a good way to tell both users and search engines that the urls have changed and where the new page is. I could have left with the old url structure but it was not perfect.
It’s like moving to a new apartment. Then it’s often needed to send post cards to your friends and tell them about the move and new address, even if it’s an anti-pattern. The best would probably stay in the same apartment, but sometimes it’s needed to move on.
@texnixe Do you say that my awesome plugin should only be used as a last resort? Whatta!
Sometimes I wish there was ìnclude in htaccess to separate custom stuff from core stuff.
Well, if you have access to the server config file, you can use includes. You would not need the .htaccess file at all, either, because all that can go into the server config.
<VirtualHost ${APACHE_IP}:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@example.com
ServerSignature Email
Include /srv/customers/xxxx/apache2/example.redirects
Use CustomerLogConfig xxxx example.com www
Use Expires
Use Deflate
DocumentRoot "/srv/customers/xxxx/vhosts/example.com/www/htdocs"
DirectoryIndex index.php
<Directory "/srv/customers/xxxx/vhosts/example.com/www/htdocs">
Use DocRootStandard
Use Kirby
</Directory>
SetEnv ServiceLevel PROD
</VirtualHost>
Use Kirby here contains the original rewrite rules from the original Kirby .htaccess.
Sure thing, I even linked to it in the Gist
I implemented my own version to 1) support static rendering via Refresh meta tags and 2) not require a function call in my templates (if a route matches a redirect it should occur without having to modify existing code, imo).
The import/export feature is neat but wasn’t relevant in my case.
I’ve tested the plugin and it does nothing…hmm
What you fill into the structure field, how the URLs are formated?
Do you have a screenshot or some hints for me?
Using my redirects.php plugin you need to add the blueprint (src/blueprints/redirect.yaml), create a page called redirects which uses said blueprint. You should then be able to add redirects using the structure field. The old URL should be relative to the root and exclude the leading slash. The new URL can be relative or absolute (including domain). Both old and new values can point to pages.
Hi @jenstornell, I thought I knew how to “call” a function & this might be an amateur question, but is this how you “call” the redirecty function in the header snippet:
@luukee That plugin doesn’t seem to exist anymore. If you still have it, there should be some info on how to use it in the readme file that accompanies the plugin.
Unless the redirect method is defined as a custom site method, your code will not work. Apart from that, if it was a $site method, you would have to call it with