logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Issue setting up single page redirects in Virtual Host
Author
MelB



Joined: 13 Oct 2021
Posts: 3
Location: Ireland

PostPosted: Fri 04 Feb '22 14:25    Post subject: Issue setting up single page redirects in Virtual Host Reply with quote

Hi there,

Apologies for asking what I imagine is such a simple question but I've been having trouble with redirects on the Virtual Host, as I'm trying to ensure a persistent experience despite single page name changes.

Yesterday I deployed a new redesign to replace a current website to a new server. Built with VueJS, Blade, PHP and CockpitCMS. Same URL, new design and content.

However, some URLs from the old website lead to a 404 on the new one as the content has changed. I need to redirect these old URLs to either the homepage or an existing related page on the site.

I want to add these redirects to the Virtual Hosts and not create a .htaccess like a lot of people recommend online, as all my config is in the .conf file for this website.

For example, on the old site we may have a URL like website.co.uk/claims and I want to redirect that to website.co.uk/contact. I've tried the following in the Virtual Hosts:

Code:
<VirtualHost *:80>
        ServerName website.co.uk
        DocumentRoot /var/www/website/htdocs/public

        Redirect permanent /claims /contact


Or
Code:
Redirect permanent /claims https://www.website.co.uk/contact


Or
Code:
Redirect 301 https://website.co.uk/claims  https://website.co.uk/contact


I test and reload the server but it still sends to a 404 - I'm just not sure where I'm going wrong, although I imagine it's very simple Embarassed

Any pointers would be really appreciated, please let me know if I've let out any useful information Smile thank you in advance
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 348
Location: UK

PostPosted: Fri 04 Feb '22 21:58    Post subject: Reply with quote

I can see why you're confused.

In practice, the Redirect directive only seems to replace the first URL path string with the second string, leaving any remaining path unchanged. So http://hostname/claims/xyz gets redirected to http://hostname/contact/xyz. This may not be what you want, and may be the cause of your 404 errors.

Suggest you try RedirectMatch instead, discarding the remaining path of the request URL from the redirect target, e.g.
Code:

RedirectMatch permanent "/\bclaims\b(.*)" "/contact"

Use browser devtools (shift + ctrl + I) to check what response location headers are actually received by the browser.
Back to top


Reply to topic   Topic: Issue setting up single page redirects in Virtual Host View previous topic :: View next topic
Post new topic   Forum Index -> Apache