HTaccess redirects old-age -> newpage

I am trying to add some page redirects in the default Kirby HTaccess file but its not working. Any advice? See the Redirect 301 /oldpage/ /newpage/in the code below:

# Kirby .htaccess
# revision 2022-09-15

# rewrite rules
<IfModule mod_rewrite.c>

# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on

# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder;
# otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite,
# set the RewriteBase to:
#
# RewriteBase /mysite

# In some environments it's necessary to
# set the RewriteBase to:
#
# RewriteBase /

# block files and folders beginning with a dot, such as .git
# except for the .well-known folder, which is used for Let's Encrypt and security.txt
RewriteRule (^|/)\.(?!well-known\/) index.php [L]

# block all files in the content folder from being accessed directly
RewriteRule ^content/(.*) index.php [L]

# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) index.php [L]

# block direct access to Kirby and the Panel sources
RewriteRule ^kirby/(.*) index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]


Redirect 301 /oldpage/ /newpage/


</IfModule>

# pass the Authorization header to PHP
SetEnvIf Authorization "(.+)" HTTP_AUTHORIZATION=$1

# compress text file responses
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>



Have you tried without the trailing slashes? Note that a 301 redirect is permanent (cached by browsers) and should not be used for a path that you might want to use again. So use with caution.

old-age → newpage

:grinning:
:older_woman: => :baby:

Try to move your Redirect directive at the top of the file, even before the <IfModule mod_rewrite.c> line (The Redirect directive is not part of mod_rewrite but mod_alias). At the current point, all URLs start with /index.php, so your Redirect does not match anything.

No luck, I have just tried both of these and still get redirected to my error page on /index.php

What is your environment?

Shared hosting on names.co.uk

This is my first website I have put live with Kirby.

Normally I have no trouble with redirect the old website urls to the new urls. There must be something in the htaccess stopping it.

Then you should dig deeper and provide more information. Some hints:

  • Is your webserver running on Apache and does it support .htaccess and all directives therein? I guess, this is the case, otherwise you would have even more trouble. But your hosting provider (who is out-of-date with PHP versions and totally overpriced imho, btw) does not reveal this on a first glance. You can check this by putting some garbage into the file and see what happens.
  • Does the Kirby version match the supported PHP version?
  • Do you have log files available? It is imperative to check the log files from webserver to see what happens. If possible, raise the log level.
  • To provide more help from an external point of view, we need more detailed information about your website structure on filesystem level, the details of your .htaccess file and directives therein, and other configurations. Otherwise it is just plain guessing.

The hosting is my client’s hosting so I have little control over that as they don’t wish to change. However, the PHP versions are up-to-date.

It’s an Apache Server, PHP 8.2, Kirby 3.8.2.

I’d set up route in config that does the redirecting if you can’t get it to work with .htaccess.