2

I am new to drupal and have a page set up with a bunch of links. When clicked, the links are supposed to open up a php file (player.php, located in the root directory) in a new window. However, all I get is a 404 error. When I try to navigate to the page directly, I also get a 404 error (www.mywebsite.com/player.php).

If anyone has any suggestions on how to fix this, it would be a great help!

  • Can you check their permissions ? – GoodSp33d Oct 7 '12 at 13:44
4

Make sure that your file player.php is in the right location; it should be in your Drupal root -- the same folder that has index.php. In my test, a php file at the document root was executed correctly if it was readable by the webserver -- it would run even without execute permissions. chmod 0 player.php gave me an internal server error, not a 404. You should check your permissions, but this seems to not be the issue.

Is this site using your own web server configuration file, or is it on a shared or managed ISP? Check to see if there are any rewrite rules that might be getting in the way.

The workarounds from my previous answer, below, should be unnecessary, but I will leave them here in case they may be of interest or help.

A. Put your file in a different location in the file system, and point at it with an alias.

    alias /player /srv/www/player
    <Directory /srv/www/player>
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

Put that in your Apache Virtual hosts file. If you cannot edit this file (e.g. on a shared hosting account), then this will not be an option. If you set up your vhost conf file like this, restart Apache and put your code at /srv/www/player/player.php. Access it from www.mywebsite.com/player/player.php.

B. Instead of using a standard php file, write a Drupal menu.

function mymodule_menu() {
  $items = array();
  $items['player'] = array(
    'title' => t('Player'),
    'access callback' => TRUE,
    'page callback' => '_mymodule_player',
  );
  return $items;
}

Accessing the URL www.mywebsite.com/player will then run the code in the function _mymodule_player.

See: http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7

  • 3
    I dont think thats totally right; if the file player.php exists in the web root it should be served without Drupal getting involved. There's a line in .htaccess to make sure of that. If there wasn't every existing file (including CSS, images, js, etc) would have to be served through a Drupal bootstrap – Clive Oct 7 '12 at 9:03
  • ^ +1, If file is in proper path it will be parsed/downloaded/forbidden depending on server config – GoodSp33d Oct 7 '12 at 13:42
  • 1
    Clive and kantu are right; I put my test file in the wrong location, above Docroot. :p Edited answer above. – greg_1_anderson Oct 7 '12 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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