3

After upgrading my remote server to Ubuntu 14.04 (Apache 2.4), I am unable to use my previous format where I could request URI's without calling the file extensions kind of like how pages are called in a framework like CodeIgniter.

When I call http://example.com/about I am calling about.php. This worked in Ubuntu 12.04 but now getting Page not found.

This still works on my local machine which is still 12.04 so I do not believe this to be an .htaccess issue nor do I believe it to be a sites-available file issue. Also, this is version controlled using git so everything is pretty much the same except for a couple Vars that call the site name and file paths. --CORRECTION: This is a .conf issue as stated below in my UPDATE.

I have a2enmod (mode_rewrite) on.

But to be complete, I will provide both the htaccess and sites-available files;

/etc/apache2/sites-avaialable/example.net.conf:

<VirtualHost xxx.xxx.xxx.xxx:443>
  SSLEngine On
  SSLCertificateFile /etc/apache2/ssl/domains/example.net/example.pem
  SSLCertificateKeyFile /etc/apache2/ssl/domains/example.net/example.key

  ServerAdmin webmaster@example.net
  ServerName example.net

  DirectoryIndex index.php index.html
  DocumentRoot /var/www/html/example.net/www/

  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>

  <Directory /var/www/html/example.net/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>

  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/example.net/logs/error.log
  CustomLog /var/www/html/example.net/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin webmaster@example.net
  ServerName example.net
  ServerAlias www.example.net

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.php index.html
  DocumentRoot /var/www/html/example.net/www/

  <Directory />
    Options FollowSymLinks
    AllowOverride None
 </Directory>

  <Directory /var/www/html/example.net/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>

  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/example.net/logs/error.log
  CustomLog /var/www/html/example.net/logs/access.log combined
</VirtualHost>

END example.net.conf

I should note that this is the same in my local machine where the extension-less URI calls succeed.

UPDATE:

I have removed the code to my .htaccess file as I have decided to no longer use it since it is unnecessary and slows down the server.

I currently have this set in my example.net.conf file at the bottom of both (80 and 443) VirtualHost directives:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

This works to some extent. The issue I am having is that navigating to document root -> example.com, now just shows an index of all files and directories instead of the content.

2 Answers2

6

The problem lies in the .conf file (or .htaccess if you are using that).

I had the following in my .conf file:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews
    RewriteEngine on

    RewriteCond %{REQUEST_URI} !-d
    RewriteCond %{REQUEST_URI}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
</IfModule>

I finally learned that as of Apache 2.2, you must prepend DOCUMENT_ROOT. So the following now works:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews
    RewriteEngine on

    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
</IfModule>
0

I created a configuration example that is able to execute /testclass/testmethod without the .php extension

For the rewrite rules I followed the guideline at codeigniter

Tk421
  • 250