0

I need to redirect only http://example.org/ to http://www.something-other.org/ in Apache 2.4.

Just the homepage. Nothing else. I.e. http://example.org/?page=blog or http://example.org/contact.html should NOT redirect.

All I could find was redirecting a page completely to another site like:

Redirect "/" "http://www.something-other.org/"

This is a bit better:

RewriteEngine On
RewriteRule ^/$ http:// www.something-other.org/ [L,R=301]

It redirects only the homepage, but also, if there is a query string.

rubo77
  • 2,537

1 Answers1

6

You need to use mod_rewrite:

RewriteEngine On
RewriteCond "%{QUERY_STRING}" "^$"
RewriteRule "^/$" http://something-other.org/ [L,R=301,QSD]

The QSD flag discards the query string.

Enable mod_rewrite and restart apache:

root@host:~# a2enmod rewrite
root@host:~# service apache2 restart
rda
  • 2,057