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.
Other documents go into greater detail, but this doc should help the beginner get their feet wet. The Apache module mod_rewrite is a very powerful and sophisticated module which provides a way to do URL manipulations. With it, you can do nearly all types of URL rewriting that you may need.
With it, you can do nearly all types of URL rewriting that you may need. It is, however, somewhat complex, and may be intimidating to the beginner. There is also a tendency to treat rewrite rules as magic incantation, using them without actually understanding what they do.
It is initially (for the first rewrite rule or until a substitution occurs) matched against the URL-path of the incoming request (the part after the hostname but before any question mark indicating the beginning of a query string) or, in per-directory context, against the request's path relative to the directory for which the rule is defined.
The main difference with per-server rewrites is that the path prefix of the directory containing the .htaccess file is stripped before matching in the RewriteRule. In addition, the RewriteBase should be used to assure the request is properly mapped.
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.
They go in httpd.conf. Check out the doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With