A simple way to redirect http://example.com to http://example.com/thelink with Apache

apache-2.2mod-rewriteredirectrewrite

Just starting to try to get the hang of how all the directives and options work under Apache.

I'd like to do a redirect with my one site (only running one site on the server) so that when a request comes in to http:/example.com the server automatically redirects them to a sub-url of http://example.com/mylink.

I have tried putting redirects into the file located in /etc/apache2/sites-enabled to rewrite this, but then the top level domain URL complains it isn't redirecting properly.

I think what I want is a browser redirect, and thought using

RewriteEngine On
RewriteRule ^/$ /mylink [L,R]

would work, but putting it into an .htaccess file didn't work (it redirected but immediately gave a 500 internal server error.)

Putting it into the file in /etc/apache2/sites-enabled gives a configuration error when trying to restart Apache.

I know it's something simple…but what am I missing?

Best Answer

Try a RedirectMatch, instead:

RedirectMatch permanent ^/$ http://mysite.com/mylink

They're often easier when you're after a simple redirect, whereas Rewrites come into their own when you don't want the end user to see the results.