Apache alias in .htaccess (mod rewrite question)

Hi All,

I need to replicate an alias directive within a .htaccess file (on a shared host, don’t have access to my hosts apache conf).

The directive is as follows:


Alias "/" "/var/www/core/web/index.php/"

I’ve tried various configurations of mod rewrite, but it’s not doing what I want. I’m a fish out of water with some of the more specific apache stuff… hoping we’ve got someone here who can help.

This has got me part of the way there:


Options +FollowSymLinks
RewriteEngine On

DirectoryIndex index.php

#Set the base uri
RewriteBase /mysource_matrix
#Now do some rules for redirection
#if index, don't redirect (again)
RewriteRule index.php   -
#don't redirect double-underscore dirs (symbolic links)
RewriteRule __lib       -
RewriteRule __data      -
RewriteRule __fudge     -
#redirect everything else to index.php
RewriteRule (.*)       index.php/$1 [L]

I get apache 500 internal server error when trying to use this - the problem is the last line - it’s supposed to write to a index.php symbolic link in the web root… but, it doesn’t. I’ve tried re-writing it directly to the file and that produces the same problem.

iron,

The Context line tells you that you can NOT use this directive in .htaccess (inA1.3) - that’s the problem.

Regards,

DK

iron,

Okay, I read further and wonder why you were asking about Alias!

Anyway, IF you’ve confirmed that mod_rewrite is enabled (and tested it), then

#don't redirect double-underscore dirs (symbolic links)
RewriteCond %{REQUEST_URI} !__
#redirect everything else to index.php
RewriteRule (.*) index.php/$1 [L]

I think the problem was that you were not terminating the early statements with the Last flag so mod_rewrite kept truckin’ through the code until it hit the EVERYTHING atom and dumped it all (including index.php) in the “subdirectory” for index.php. (IMHO, CRAZY code :mad: and you’re lucky you didn’t take down your server! PLEASE learn the RARE occasions when (.*) is actually the correct code to use.)

Regards,

DK

Thanks for the advice :slight_smile: I inherited this from elsewhere - lucky it hasn’t caused problems.

This is how my .htaccess file looks at the moment. It’s still throwing 500 internal server errors:


Options +FollowSymLinks
RewriteEngine On

DirectoryIndex index.php

#Set the base uri
RewriteBase /mysource_matrix
#don't redirect double-underscore dirs (symbolic links)
RewriteCond %{REQUEST_URI} !__
#redirect everything else to index.php
RewriteRule (.*) index.php/$1 [L]

Mod rewrite is on, I’m using it for other sites on the same server, double underscores are working fine, still having issues with that last bit.

Bear in mind, my alias’ work fine on a test box - it pushes everything through to the scripts landing page… the rewrite doesn’t. Are they supposed to behave in the same manner?

iron,

DirectoryIndex index.php

Options +FollowSymLinks
RewriteEngine On

#Set the base uri
RewriteBase /mysource_matrix
#don't redirect double-underscore dirs (symbolic links)
RewriteCond %{REQUEST_URI} !__
# prevent loop
RewriteCond %{REQUEST_URI} !index\\.php
#redirect everything else to index.php
RewriteRule (.*) index.php/$1 [L]

Regards,

DK

Thanks David,

It’s got me past those internal server errors … I’m still kinda stuck at the beginning again - it’s not behaving the same as an alias directive. Not to worry though, at least it’s given me a place to start.

Thanks for your help :wink:

iron,

What’s it doing now? Add an R=301 flag so you see the redirect (GREAT for testing).

Regards,

DK

http://httpd.apache.org/docs/2.0/mod/core.html#acceptpathinfo

I usually put the slash at the end of Rewritebase.
RewriteBase /mysource_matrix/

Also, your code can be further optimized like this, if you prefer. :slight_smile:
(Providing the code does what you want.)


DirectoryIndex index.php

Options +FollowSymLinks
RewriteEngine On

#Set the base uri
RewriteBase /mysource_matrix/
#don't redirect double-underscore dirs (symbolic links)
# prevent loop
#redirect everything else to index.php
RewriteRule !^/*(__|index\\.php) index.php%{REQUEST_URI} [L]

Added the extra slash, but still the same problem.

I get:


No input file specified.

I think this is being generated by apache, the code I’m using doesn’t (well shouldn’t) produce this flavour of error.

I tried to use acceptpathinfo, but get a 500 internal server error. I’m not 100% certain on the apache version so it’s either my implementation of the example, or my version. Have to check up on that.

That flag is great, I can see it re-directing to the correct page (I’ve tried both real path, and the path to the symbolic link I created).

E.g:

http://mysite.com/example

redirects to

http://mysite.com/index.php/example

The script only actually runs however, when I use:

http://mysite.com/index.php

Nothing else will work at the moment.

No input file specified.

Isn’t it coming from PHP?
If so, there is something wrong with your php setup.

You are using php-cgi and not putting Action directive, or something like that.

You’re not getting any inputs because AcceptPathInfo is not enabled. For that to work, you need two things (from docs):

  1. Apache 2.0.30 or higher
  2. AllowOverride FileInfo at higher levels

If you’re using Apache 1.3 then there’s a different trick but I forget what it is, so check the 1.3 docs. :slight_smile:

Crap, yeah it’s 1.3.33 - the host is lagging behind in php 5 version upgrades as well (although not related to the scripts I’m running).

I’ll have a hunt around in the docs and see what I can find. Thanks LinhGB

@extras - I’m 100% certain it’s not the php app reporting this, I’ve done some testing on this.

Also,

RewriteRule !^/*(__|index\.php) index.php%{REQUEST_URI} [L] makes the extension for index.php/path/to/request.extension and that doesn’t make any sense at all! Perhaps a ? before the %{REQUEST_URI} might help?

Regards,

DK

index.php/path/to/request

that’s exactly the string that I want - the script interprets $_SERVER[‘PHP_SELF’], so that url is perfectly ok. It’s working like that in it’s current state (ie the URL), but it’s not running the appropriate php script.

I can’t find any doco on getting AcceptPathInfo working in apache 1.3.x unfortunately - anyone got any bright ideas?

iron,

Have you tried the Options +MultiViews (or did I miss that in an earlier post)?

Regards,

DK

I’ve added it, still no joy - terribly frustrating issue that could be solved by the host upgrading apache, but I don’t think I’ll see that any time soon.

This is a similar CMS to mysource matrix:

http://ez.no/doc/ez_publish/technical_manual/3_6/installation/virtual_host_setup/virtual_host_example

That Vhost conf works for 1.3. What you need to look at is how to handle PATH_INFO in Apache 1.3. What’s also important is whether your PHP is running as a CGI or as Apache module. If I remember correctly, if it’s CGI, you’re out of luck.

Btw if you’re really running MySource Matrix, forget a shared webhosting account. Think big fat dedicated server(s).

If the PHP needs PATH_INFO, it means it’s running as CGI, IMO.

Then you need to set Action directive, most probably.
AddType application/x-httpd-php .php

replace with the correct path (from document root).

Action application/x-httpd-php “/php/php.exe”

Also, PHP-cgi (4 or 5) can be installed in your own directory.
We’ve tested that on site5 when they were not supporting php5, yet.

You may have to compile it at home using same (or similar) OS and with the same directory structure, though.