I have installed CMSMS 2.2.21 that replaces our old website and did create a new website entirely. Using pretty URL.
because of google results that link to our old website, I need to redirect some pages. I had hoped to be able to do this in .htaccess as I always do with my static websites.
Redirect geschichte/stiftung https://www.domain.ch/geschichte
But nothing works. I always get a white page with Error message on top, instead of a redirected existing page.
I would also be okay with just 404 going to the home page instead.
ErrorDocument 404 https://www.domain.ch
I already identified that it is specifically RewriteRule ^(.+)$ index.php?page=$1 [QSA] that prevents this. Without it, at least the ErrorDocument 404 works.
So how can this be solved?
<IfModule rewrite_module>
RewriteEngine on
# If your CMSMS installation is in a subdirectory of your domain, you need to specify the relative path (from the root of the domain) here.
# In example: RewriteBase /[subdirectory name]
RewriteBase /
# Rewrites URLs in the form of /parent/child/grandchild but only rewrites if the requested URL is not a file or directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
.htaccess error handling not working
Re: .htaccess error handling not working
You may need to share more of your .htaccess file, there's a few things that can cause it to not work when using both rewrites and redirects.
Not getting the answer you need? CMSMS support options
Re: .htaccess error handling not working
well its only what is recommended by cmsms with pretty URL
Code: Select all
# This file is specific to Apache configurations.
# It attempts to optimize traffic and configuration for your CMS Made Simple™ website.
# Many options are disabled by default as some providers do not allow you to override some of these settings in the .htaccess file.
#
# Attempt to override some PHP settings.
# These settings may be helpful on some hosts if your default configuration does not meet CMSMS's minimum requirements,
# and your host has given your account appropriate permissions.
#
#php_value upload_max_filesize "10M"
#php_value session_save_path "tmp/cache"
#php_value session.cookie_httponly true
#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off
#
# Disallow directory indexes. This can be an important security enhancement.
#
#Options -Indexes
#
# Don't allow the browser to know the type of signature.
#
ServerSignature Off
#
# Allow the Apache server to follow symbolic links. This is usually not necessary.
#
#Options +FollowSymLinks
#
# The following is to enable pretty URLs, only applicable if url_rewriting is set to 'mod_rewrite' in the config.php
#
<IfModule rewrite_module>
RewriteEngine on
# If your CMSMS installation is in a subdirectory of your domain, you need to specify the relative path (from the root of the domain) here.
# In example: RewriteBase /[subdirectory name]
RewriteBase /
# Rewrites URLs in the form of /parent/child/grandchild but only rewrites if the requested URL is not a file or directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
#
# The following are highly recommended security settings for files in your CMSMS install that should not be browsed directly.
#
RedirectMatch 403 ^/.*\.htaccess$
RedirectMatch 403 ^/.*\.log$
RedirectMatch 403 ^/.*\.ini$
RedirectMatch 403 ^/.*config\.php$
RedirectMatch 403 ^.*/doc/.*$
RedirectMatch 403 ^.*/lib/.*\.php$
RedirectMatch 403 ^.*/tmp/.*\.php$
RedirectMatch 403 ^.*/modules/.*\.php$
RedirectMatch 403 ^.*/uploads/.*\.php$
RedirectMatch 403 ^.*/assets/.*\.php$
RedirectMatch 403 ^.*/assets/.*\.tpl$
#
# The following are performance optimizations and security enhancements for content that is served by your CMSMS installation.
#
<IfModule mod_headers.c>
# Disable Last-Modified for performance
Header unset Last-Modified
# Disable ETags
Header unset ETag
FileEtag None
# For Security
Header set X-Frame-Options "SAMEORIGIN"
</IfModule>
#
# The following setups compression for content, if compression is enabled on the server.
#
<IfModule deflate_module>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/html text/xml image/gif image/jpeg image/png image/ico text/javascript application/x-javascript application/javascript application/json application/pdf
</IfModule>
# Force www:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Re: .htaccess error handling not working
I'm not seeing your redirects there. The location of them may be part of the issue, so we need the full picture.
Not getting the answer you need? CMSMS support options
Re: .htaccess error handling not working
try following approach (respect trailing slashes in your case) for single redirectsRedirect geschichte/stiftung https://www.domain.ch/geschichte
Code: Select all
Redirect 301 /geschichte/stiftung https://www.domain.ch/geschichte/
Code: Select all
Redirect 301 /geschichte/stiftung /geschichte/
Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)altewebsite\.de$ [NC]
RewriteRule ^http://neuewebsite.de%{REQUEST_URI} [L,R=301]
Re: .htaccess error handling not working
thanks. I did place them on top, in the middle or at the end and had the same result.
But I found another solution. I found out CMSMS can handle 404 errors internally.
- I created a content page of type Error document
- I gave it an empty layout
- I set its Meta content to <meta http-equiv="refresh" content="0; url=https://example.com/"> to go to the home page
it is not a specific redirect for certain links but general, but for the moment it does the trick.
But I found another solution. I found out CMSMS can handle 404 errors internally.
- I created a content page of type Error document
- I gave it an empty layout
- I set its Meta content to <meta http-equiv="refresh" content="0; url=https://example.com/"> to go to the home page
it is not a specific redirect for certain links but general, but for the moment it does the trick.