2

Here is what I am trying to do:

  • domain is thinkingmonkey.me
  • domain has 127.0.0.1 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
</Directory>

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 thinkingmonkey.me/runs with no trailing slashes I get 404 not found.

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

5
  • 2
    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?
    – jade
    Jan 15, 2012 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. Jan 15, 2012 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. Jan 15, 2012 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?
    – jade
    Jan 15, 2012 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. Jan 15, 2012 at 22:19

1 Answer 1

3

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
</Directory>

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? :)

2
  • 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.
    – jade
    Jan 15, 2012 at 22:43
  • ha ha nice! :). Jan 15, 2012 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .