Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I use apache mod_rewrite with an Alias ? I have a test directory that contains the files: correct.html index.html test_httpd.conf wrong.html I would like an example rule using an alias that directs any requests to wrong.html be redirected to correct.html. And another example rule that directs any requests for any files in the directory test to point to correct.html Here is what I have tried in my test_httpd.conf:

#DocumentRoot /var/www/localhost/htdocs/test
Alias /test /var/www/localhost/htdocs/test/
#<Directory /var/www/localhost/htdocs/test>
#<Directory /test>
<Directory test>
  RewriteEngine On
  #RewriteRule ^*$ rewriteme.html [R]
  RewriteRule ^wrong.html$ correct.html [R]

I am on apache 2.4.6-r2 on Gentoo.

share|improve this question
Try to add a RewriteBase /test/ within your Directory block. PS: you should have <Directory /var/www/localhost/htdocs/test/>, not <Directory test>. – julp Oct 3 '13 at 17:11
That gives me a:Not Found The requested URL /var/www/localhost/htdocs/test/correct.html was not found on this server. – turtle Oct 3 '13 at 17:44
#DocumentRoot /var/www/localhost/htdocs/test Alias /test /var/www/localhost/htdocs/test/ <Directory /var/www/localhost/htdocs/test/> #<Directory /test> #<Directory test> RewriteBase /test/ RewriteEngine On #RewriteRule ^*$ rewriteme.html [R] RewriteRule ^wrong.html$ correct.html [R] </Directory> – turtle Oct 3 '13 at 17:45
Nevermind I had to clear the browser cache. Yes it works! Thanks. It only works with the RewriteBase /test and I think the trailing / was not necessary. – turtle Oct 3 '13 at 18:06
Essentially mod_rewrite can not use an alias? – turtle Oct 3 '13 at 18:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.