Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Here is what I am trying to do:

  • domain is
  • domain has as IP addr
  • mod_alias is installed.

I have a conf file called directories.conf. In which I have all the configuration pertaining to directories. directories.conf is included in httpd.conf

My directories.conf has

Alias /runs /xhprof/xhprof_html

<Directory /mysite/xhprof/xhprof_html>
    Order allow,deny
    Allow from all
    AllowOverride All

In /mysite/xhprof/xhprof_html/.htaccess. I have the following:

RewriteEngine on
RewriteBase /runs
RewriteRule  .*  index.php

All I am trying to do is to direct any request under /mysite/xhprof/xhprof_html/ to index.php.

When I request for with no trailing slashes I get 404 not found.

So, I infer that RewriteBase is not working.
What am I doing wrong?

share|improve this question
In the Alias line, is it a typo or intentional that "/mysite/" isn't included? The right-hand-side of an Alias directive should be the actual path on the filesystem. Also, can you post the last couple lines of your /var/log/apache2/access.log and .../error.log? – jon Jan 15 '12 at 20:40
@jon It was intentional. Thanks for mentioning it. Alias: Since it was not mentioned anywhere in the docs I thought a relative path could be given. – ThinkingMonkey Jan 15 '12 at 21:53
@jon although, index.php is loading, the js, css which is present in the folder /mysite/happ/xhprof/xhprof_html/css does not. Looking into this now. – ThinkingMonkey Jan 15 '12 at 21:59
The RewriteRule you have will redirect any URL starting with http://.../runs to index.php, including those starting with http://.../runs/css/. Do you want to redirect only http://.../runs and http://.../runs/ to index.php? – jon Jan 15 '12 at 22:14
@jon ya realised that sometime back, writing rules to redirect for js & css folders. Thanks. If possible please post you comment as an answer. Will accept it. – ThinkingMonkey Jan 15 '12 at 22:19
up vote 3 down vote accepted

There are a couple things in play here. First, the Alias directive wants its right-hand-side to be an absolute, physical path on the server: you want

Alias /runs /mysite/xhprof/xhprof_html

<Directory /mysite/xhprof/xhprof_html>
    Order allow,deny
    Allow from all
    AllowOverride All

Secondly, the RewriteRule RewriteRule .* index.php matches not only http://.../runs, but also any URL beginning with http://.../runs/, even, for example, http://.../runs/css/.... There are a couple ways to get around that.


Option 1: you could have a RewriteRule only redirect the root of the runs to index.php:

    RewriteRule ^$ index.php
    RewriteRule ^/$ index.php


Option 2: you could have the your mod_rewrite configure special-case things that exist as files, and redirect everything else to index.php

    # Require the path the request translates to is an existing file
    RewriteCond %{REQUEST_FILENAME} -f
    # Don't rewrite it, but do stop mod_rewrite processing
    RewriteRule .* - [L]

    # Now, redirect anything into index.php
    RewriteRule .* index.php


Option 3: you can special-case certain URLs, and redirect everything else to index.php

    RewriteCond $1 !^css/
    RewriteCond $1 !^js/
    RewriteRule .* index.php


Option 4: if you want any URL mapping to a directory to show an index.php file (like index.html), there's a really simple way, which is probably what you want. You can put the following either in a .htaccess or inside the <Directory> block in directories.conf:

    DirectoryIndex index.php index.html


Footnote: the RewriteRules above basically throw away all of the URL for any request that ends up mapping to index.php. That includes query-strings, so /runs/?foo=bar is the same as /runs/. If that's not what you want, you need a rule like

    RewriteRule ^(.*)$ index.php/$1 [QSA]

which preserves both the path-info (the $1 part) and the query-string ("QSA" = "query-string append".)

Have I written way too much yet? :)

share|improve this answer
This question had good timing: I reworked a .htaccess that dealt with basically exactly this stuff really recently, so it's all really fresh in my mind. – jon Jan 15 '12 at 22:43
ha ha nice! :). – ThinkingMonkey Jan 15 '12 at 23:18

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.