Mario Parra Mario Parra - 2 months ago 22
Apache Configuration Question

.conf file to redirect naked domain to page

I have a Craft CMS site, which has generated a specific page–let's call it "domain.com/page-x"–and I want to edit a .conf file for a new domain to redirect domain2.com straight to this page.

Thing is that since it's not a flat file, I can't use

DocumentRoot
to point directly to it in the server, so I've used
Redirect permanent
, but I'm not sure if that'll work at intended:

<VirtualHost *:80>
ServerName domain2.com
ServerAlias www.domain2.com

Redirect permanent / domain.com/page-x

CustomLog /var/log/httpd/website.lc-access.log combined
ErrorLog /var/log/httpd/website.lc-error.log

</VirtualHost>


Is this correct?

Answer

The correct way:

Redirect permanent / http://domain.com/page-x/
  1. Always include the scheme (http/https)
  2. Always match slashes in source and target.