Apache RewriteBase Problem

Five days ago my friend gave me a problem. Problem is bellow

His client gave him a job that fixing the broken link of the site.

That site use rewrite engine to rewrite the .html file to .php file. Also the server uses the virtual hosts.

We saw that the rewrite rules are correctly written and the expected files are present. But the link showed that internal server error and it didn’t find the file.

We have noticed that the server find the files in a directory. So we made a script to find the directory of that script, we have noticed that it is not the same directory. But we didn’t find any problem with the rewrite rules. here is the content of the .htaccess file

# enable mod_rewrite

RewriteEngine on
# correct urls for yahoo bot

RewriteCond %{REQUEST_URI} !\..+$

RewriteCond %{REQUEST_URI} !/$

RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]


# mod_rewrite rules for ROOT category

RewriteRule ^index([0-9]+).html$ index.php?category=0&page=$1 [QSA,L]


# mod_rewrite rules for categories pages with HTML path option disable

RewriteRule ^(.*)/$ index.php?category=$1 [QSA,L]

RewriteRule ^(.*)/index([0-9]+).html$ index.php?category=$1&page=$2 [QSA,L]


# mod_rewrite rule for suggest listing page

RewriteRule report-listing.php$ report-listing.php [QSA,L]


RewriteRule ^([a-z]+)-listings.html$ listings.php?view=$1 [QSA,L]

RewriteRule ^([a-z]+)-listings([0-9]+).html$ listings.php?view=$1&page=$2 [QSA,L]


# mod_rewrite rules for view listing page

RewriteRule ^([^/]+)-l([0-9]+).html$ view-listing.php?cat=&title=$1&id=$2 [QSA,L]

RewriteRule ^(.*)/([^/]+)-l([0-9]+).html$ view-listing.php?cat=$1&title=$2&id=$3 [QSA,L]


# mod_rewrite rules for additional pages

RewriteRule ^p(.*).html$ page.php?name=$1 [QSA,L]


# mod_rewrite rules for error pages

RewriteRule ^([0-9]+).htm$ error.php?error=$1 [QSA,L]


# mod_rewrite rules for suggest category page

RewriteRule ^suggest-category-([0-9]+).html$ suggest-category.php?id=$1 [QSA,L]


RewriteRule ^LICENSE.htm$ LICENSE.htm [QSA,L]


# mod_rewrite rules for categories pages

RewriteRule ^(.*)_([0-9]+).html$ index.php?category=$1&page=$2 [QSA,L]

RewriteRule ^(.*).html?(.*)$ index.php?category=$1&$2 [QSA,L]

RewriteRule ^(.*).html$ index.php?category=$1 [QSA,L]


ErrorDocument 500 500.htm

ErrorDocument 404 404.htm

ErrorDocument 403 403.htm

ErrorDocument 401 401.htm

After that we made some .html file and put thats in the server and delete the .htaccess file to check that without rewrite rules it works or not. That works!!! So we became confirm that the problem is in rewrite rule.

But the rewrite rules is correct. So where is the problem??????

After googling we have found something about RewriteBase here.

Few days ago i have studied about the virtual hosts of apache, there i have found that the RewriteBase is can be configured for every virtual host. So that I think maybe we found the solution.

Then I have added just one line after the followings



# enable mod_rewrite

RewriteEngine on

#this line is addedd

RewriteBase / 

And the things work like a magic.

Have you got this problem before??? If so then what is your experience???

Comments (16)

Apache Virtual host confguration in Linux (Ubuntu)

Some days ago I have posted how to configure apache virtual host in windows. You can find it here. Now I will describe how to configure virtual host in Linux. It’s all most same. This will take few steps

1. Locating the config file:

You first work is to find the config file.

  1. In most setups, apache takes up residence in /usr/local/apache. If so, chances are your configuration file is /usr/local/apache/conf/httpd.conf. I am using Ubuntu (Gutsy Gibbon) and I have found it here.
  2. If not then let us find it.
$ find / -type f -name httpd
./usr/local/apache/bin/httpd

2 . Now configure the httpd.conf

The virtual host config starts with, the virtual host tag. Anything between the opening (<VirtualHost *>) and the closing (</VirtualHost>) tags is the configuration.

I am going to setup the test.local .

# The localhost in the VirtualHost tag, tells apache that any request with test.local from localhost

NameVirtualHost localhost

<VirtualHost localhost>

# This should be self-explanatory, the name and port under which the server

# identifies itself. If the port is 80 (default) it is not necessary to include it.

# If this is not set to a valid DNS name, server-side redirects will fail.

ServerName test.local

#

ServerAdmin admin@test.local

# Place where the documents for this domain live. replace it by your own

DocumentRoot /var/www/test

</VirtualHost>

This is the basic setup.

3. Last change

Obviously, if you typed http://test.local in your browser, it would not be found by your Internet provider’s DNS server. We’re next going to edit another file to work around that. The second file you need to edit is called hosts, with no file extension. It will enable you to enter specific addresses for specific domains instead of using a DNS lookup. The normal location for this file is:

/etc/hosts

Just go to the bottom of the file, below all the comments and any existing entries and add the following two lines:

127.0.0.1 test.local

That’s all you need to do there. Save and close the hosts file.

Lastly :

You’re almost done! The only remaining thing you need to do is to re-start the Apache server. You need to do this because Apache only reads the configuration file when it first starts up.

Can you browse http://test.local???

Comments (7)

Installing Adobe Flash Player in Ubuntu

Here i will describe how to install .tar.gz.

First download the .tar.gz file. Go to http://www.adobe.com and click on the Get Adobe Flash Player button. Make sure you use a browser from your Linux desktop; if you use a Windows browser you will be redirected to the Windows version of the Flash Player 9. Provided you use a Linux browser, you will be redirected to the download page of the Linux version of the Flash Player 9. On the download page you will get a Flash Player .tar.gz file and download it to your computer (in my case I downloaded it to /home/tapos/Desktop).

Now open a terminal then go to the directory like this:

cd /home/tapos/Desktop ##replace this as your download directory

Then ..

tar xvfz install_flash_player_9_linux.tar.gz
cd install_flash_player_9_linux/

sudo ./flashplayer-installer

then the process is bellow.

You will be asked few questions. Just answer this. The red one’s is the answer. You may face one problem with installation directory of the Browser. Please check your usr/lib directory to get the correct installation path.

Copyright(C) 2002-2006 Adobe Macromedia Software LLC. All rights reserved.
Adobe Flash Player 9 for Linux
Adobe Flash Player 9 will be installed on this machine.
You are running the Adobe Flash Player installer as the “root” user.
Adobe Flash Player 9 will be installed system-wide.
Support is available at http://www.adobe.com/support/flashplayer/
To install Adobe Flash Player 9 now, press ENTER.
To cancel the installation at any time, press Control-C. <– <ENTER>
NOTE: Please exit any browsers you may have running.
Press ENTER to continue… <– <ENTER>
Please enter the installation path of the Firefox, Netscape,
or Opera browser (i.e., /usr/lib/mozilla):
<– /usr/lib/firefox
dir= /usr/lib/firefox
WARNING: An older version of the Adobe Flash Player has been detected in
/usr/lib/firefox/plugins.
The installer will overwrite this existing binary.
———– Install Action Summary ———–
Adobe Flash Player 9 will be installed in the following directory:
Browser installation directory = /usr/lib/firefox
Proceed with the installation? (y/n/q): <– y
Installation complete.
Perform another installation? (y/n): <– n
Please log out of this session and log in for the changes to take effect.
The Adobe Flash Player installation is complete.

Now check your installed plugins in firefox. Just open firefox and type about:plugins and check it. I have following view.

Flash Installing

What is your experience??

Comments (29)

লিনাক্সে প্রথম বাংলায় লেখা

অাজ প্রথম বাংলায় লিখলাম। মজা লাগতেছে।

অাপনার অনুভূতি কি?

Comments (2)

$this variable & self class name

$this is a special variable of an object. Using $this, a member variable or methods of the class can be accessed from anywhere inside of that class.

self is a reserve class name which is also used inside the object itself.

For the static members and static methods and constants, self class name is used instead of $this. So when you use static method or variables and call it inside the same class you must use the self not the $this.

Comments (5)

Joomla 1.5 Stable Version has Released

It’s a big day for hundreds of thousands of web sites built on top of the popular open-source Joomla! CMS. After over two years of development and reworking, Joomla! 1.5 (stable) has released to the user community today, combining a brand new object-oriented PHP framework with the content management system’s ease of use and its multitude of functional extensions. You can download it from here

Comments (3)

Singleton Pattern in PHP

Singleton design pattern is used to control the instantiation of a class to an Object. The singleton pattern is implemented by creating the class with a method that creates an instance if one does not exists and the constructor of the class is private.

We can implement this in PHP-5 as followings

<?php

class Singleton {

// object instance

private static $instance;

//constructor
private function __construct() {}

//clone
private function __clone() {}

//make instance
public static function getInstance() {

if (self::$instance === null) {//checking the previous instance

self::$instance = new self;

}

return self::$instance;

}

//the other methods of this class

public function doAction() {

}

}

?>

<?php

//usage

Singleton::getInstance()->doAction();

?>

In this example we can see that a static variable $instance is declared to hold the instance of the class. Also the constructor and clone method is private, this ensure the controlling of making the new object of that class.

After that we make a public function getInstance to make an instance of the class. This function return a new instance if no instance of the class is not exists, if exists this return that instance.

AND the uses is simple just use $class_name->getInstance() to make a new instance of the class.

Thanks

Comments (2)

Older Posts »
Follow

Get every new post delivered to your Inbox.