Home mod_rewrite entire website to front page ONLY of new website
Reply: 0

mod_rewrite entire website to front page ONLY of new website

user9933 Published in September 20, 2018, 4:35 pm

Now I've written dozens of redirects in my time, some with tricky regex, some more tame, but today, the very simplest redirect is stumping me on a CentOS server, running Apache 2.2.3.

All I'd like to do is redirect every single request on an old domain, regardless of path and query string, to the front page only of a new site. This is why, for example, a mod_alias Redirect directive isn't appropriate, since it appends the path to the new address.

In an Apache conf file, where the virtual server is defined, I now have

<VirtualHost THE.IP.ADDRESS:80>
        DocumentRoot "/var/www/html/SITE_ROOT"

        ServerName OLD_DOMAIN.com

        <Directory "/var/www/html/SITE_ROOT">

                Options  FollowSymLinks
                RewriteEngine On
                RewriteRule ^$ https://NEW_DOMAIN [R=301,L]

                AllowOverride None

While the redirect to https://NEW_DOMAIN occurs as expected, the path of the original request is always appended, leading to 404 errors on the new site.

For example, visiting http://OLD_DOMAIN.com/asdf

redirects to https://NEW_DOMAIN.com/asdf

...when I'd actually want to arrive at https://NEW_DOMAIN.com/

Why is the path being appended, even though I'm not collecting a pattern match, and am not specifying such a match in the destination?

There are plenty of answers like this on SO already:

  • Apache redirect to a clean URL
  • https://stackoverflow.com/a/11590814/1738274

But I can't find a discrepancy comparing these solutions against my own configuration. Any ideas?

share|improve this question
  • The only difference I spot is the missing trailing / in the RewriteRule ^$ https://NEW_DOMAIN. Maybe you can try with RewriteRule ^$ https://NEW_DOMAIN/ – Simonluca Landi Feb 13 at 13:32
  • I'm afraid I'd already tried that, but sadly to no effect... Thank you though! – J Griffiths Feb 13 at 13:44
  • Have you cleared browser history, just to make sure you’re not tricked by the browser cache? (Some browsers cache redirects really tenaciously, so if you tested this before with a different htaccess setup which did intentionally include the path, this might be the cause.) – CBroe Feb 13 at 13:55
  • Thanks, but I've tried different browsers and even entirely different devices- and at no point did I have it configured to include the path. While this tenacious caching has often been the source of my problems in the past, this time for once, it is not. Thanks though! – J Griffiths Feb 13 at 14:15

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.326698 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO