Page 1 of 1

.htaccess error handling not working

Posted: Tue Sep 03, 2024 2:24 pm
by thomahawk
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>

Re: .htaccess error handling not working

Posted: Tue Sep 03, 2024 3:47 pm
by DIGI3
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.

Re: .htaccess error handling not working

Posted: Tue Sep 03, 2024 4:22 pm
by thomahawk
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

Posted: Tue Sep 03, 2024 10:15 pm
by DIGI3
I'm not seeing your redirects there. The location of them may be part of the issue, so we need the full picture.

Re: .htaccess error handling not working

Posted: Wed Sep 04, 2024 7:27 am
by creopard
Redirect geschichte/stiftung https://www.domain.ch/geschichte
try following approach (respect trailing slashes in your case) for single redirects

Code: Select all

Redirect 301 /geschichte/stiftung https://www.domain.ch/geschichte/
or if it's the same domain this will suffice

Code: Select all

Redirect 301 /geschichte/stiftung /geschichte/
for complete URL redirects

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

Posted: Wed Sep 04, 2024 8:18 am
by thomahawk
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.