Can apache rewrite rules go in httpd.conf

Ben Paton picture Ben Paton · Oct 17, 2012 · Viewed 19.7k times · Source

How do I create a simple apache rewrite rule to rewrite:

http://domain.com/vanity to http://domain.com/foo/

Also can rewrite rules go in httpd.conf or do they have to go in a .htaccess file?

Thanks in advance.

Answer

artfulrobot picture artfulrobot · Jun 26, 2013

Put this in your website's <virtualhost>.

RewriteEngine On
RewriteRule ^/vanity$ /foo/ [L]

The [L] will silently redirect, so the user will still see /vanity in the URL. You could use [R] to force a redirect.