Hi All,

we have built web site in PHP, Mysql Database and Apache web server. Site is running fine on localhost(Window) but when we try to deploy it on our test environment (ubuntu 12.04.2 platform) .htaccess is not working. I am not getting any error like 500 Internal server error or any thing, index page is loading but after that none of the pages are loading.

I have enabled mod_rewrite on apache also changed AllowOverride All in /etc/apache2/sites-available/default, still its not working.

Same files when i deploy on Linux shared hosting is working fine. How can we solve this. kindly share your inputs.

Below are the functions which are used in router class

public function loader() 
 { 

/*** check the route ***/ 
$this->getController(); 
/*** if the file is not there diaf ***/ 
if (is_readable($this->file) == false) 
{ 

$this->file = $this->path.'/error404.php'; 
                $this->controller = 'error404'; 
} 
/*** include the controller ***/ 
require $this->file; 
/*** a new controller class instance ***/ 
$class = $this->controller . 'Controller'; 
$controller = new $class($this->registry); 
/*** check if the action is callable ***/ 
if (is_callable(array($controller, $this->action)) == false) 
{ 
$action = 'index'; 
} 
else 
{ 
$action = $this->action; 
} 

/*** run the action ***/ 
$controller->$action(); 
 } 
 /** 
 * 
 * @get the controller 
 * 
 * @access private 
 * 
 * @return void 
 * 
 */ 
private function getController() { 


/*** get the route from the url ***/ 
$route = (empty($_GET['rt'])) ? '' : $_GET['rt'];  
if (empty($route)) 
{ 
$route = 'index'; 
} 
else 
{ 
/*** get the parts of the route ***/ 
$parts = explode('/', $route); 

$this->controller = $parts[0]; 
if(isset($parts[1])) 
{ 
echo $this->action = $parts[1]; 
} 
} 
if (empty($this->controller)) 
{ 
$this->controller = 'index'; 
} 
/*** Get action ***/ 
if (empty($this->action)) 
{ 
$this->action = 'index'; 
} 

/*** set the file path ***/ 
$this->file = $this->path .'/'. $this->controller . 'Controller.php'; 
}  

below is the .htaccess file

RewriteBase /var/www/pepnew/
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]

Below is the default file on /etc/apache2/sites-available

<VirtualHost *:80> 
        ServerAdmin webmaster@localhost 

        DocumentRoot /var/www 
        <Directory /> 
                Options FollowSymLinks 
                AllowOverride All 
        </Directory> 
        <Directory /var/www/> 
                Options Indexes FollowSymLinks MultiViews 
                AllowOverride All 
                Order allow,deny 
                allow from all 
        </Directory> 

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
        <Directory "/usr/lib/cgi-bin"> 
                AllowOverride None 
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
                Order allow,deny 
                Allow from all 
        </Directory> 

        ErrorLog ${APACHE_LOG_DIR}/error.log 

        # Possible values include: debug, info, notice, warn, error, crit, 
        # alert, emerg. 
        LogLevel warn 

        CustomLog ${APACHE_LOG_DIR}/access.log combined 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
        Options Indexes MultiViews FollowSymLinks 
        AllowOverride None 
        Order deny,allow 
        Deny from all 
        Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 

</VirtualHost>  

Did you reload Apache after changing /etc/apache2/sites-available/default? To do that run:

sudo service apache2 reload

yes i have restarted Apache server

The configuration seems fine to me. It could be an ownership/permission issue for the .htaccess file, check it with:

ls -l .htaccess

The owner and the group should be the user that runs apache, usually www-data and as permission you can use 644, so:

sudo chown www-data:www-data .htaccess
sudo chmod 644 .htaccess

I have changed the ownership of the file, still page is not loading

sudo chown www-data:www-data .htaccess
sudo chmod 644 .htaccess

The only thing I can think is to check Apache logs and if also the other files and directories are owned by the same user running Apache. Or it could be the browser cache, you can try to run cURL to check if you get the page or an error:

curl --head http://localhost/page

Or, from the browser, append a random number to the link: http://localhost/page?2134

I don't have any other ideas, good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.