View Full Version : Installing mod_rewrite on vps

06-12-2007, 06:00 PM
What is the best way to enable mod_rewrite in Apache on a non-primary domain of a Westhost vps? I'm going to need very specific instructions.


06-13-2007, 06:59 AM

You well need to edit the /ect/httpd/conf/httpd.conf file in a plain text editor. Open up the file and scroll down to the bottom where you see the entry for the secondary domain. It should look something like this:

<VirtualHost *>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /path/to/www/root
Inside the VirtualHost tags you can add directives to make the secondary domain react as your main domain does. Add the code below inside those tags:

<Directory "/path/to/www/root">
Options FollowSymLinks MultiViews Includes ExecCGI
AddHandler cgi-script .cgi .pl .py .sh
AllowOverride All
Order allow,deny
Allow from all
The first two directives inside the <Directory> tag are not needed for mod_rewrite but might be something you well want at some point. It allows you to link to or set up a directory that well process cgi and perl scripts. This pretty much sets up your second domain to react as your main domain does.

Once you have made the changes to the file and uploaded back to your account (make sure you have a back up of the original file!) you can go to your site manager and restart the VPS.

When I go to upload an httpd.conf file that I have changed I first rename the old one on the server before I upload my new one. That is what I mean by back up the original above. That way if for some reason you have made a mistake in the file which crashes your site when you restart :) you can go back in and delete the file you uploaded and rename the back up.

06-14-2007, 04:59 PM
So, just to make sure I understand:

When I do this, my secondary domain will now show the contents of /var/www/html (which is the same content as the primary domain).

The primary domain needs redirected elsewhere? (not sure how).

If this is the case, then mod_rewrite can only be enabled for one domain on the vps?

Just trying to understand the ramifications of making this change.

Thanks for your expertise,

06-14-2007, 08:50 PM
Sorry I was not clear. The "/path/to/www/root" would be the path where your second domain is pointed to. So when you open up the httpd.conf and scroll down to the bottom where you see the secondary domain <VirtualHost> your see the path you set next to DocumentRoot and you want to reproduce that in the <Directory> tag. Hope that makes it clear.

09-02-2008, 08:10 AM
Hello, I did this for a second domain (which points at another dir below /www and sibling to /html, that is /var/www/html-p).
With the browser I can now access .htm and .css files, but .php returns empty.

I also did the SSH thing :) so executed php index.php but it quickly returns blank; whereas it works like a charm from subdirs below the main www/html site.

What am I missing?

Many thanks for your patience,

-- update 1
I also added .php to the AddHandler line, now I get an error; in the error log the following line is thrown:
Permission denied: exec of '/var/www/html-p/index.php' failed

-- update 2
I chmod'ed index.php to 744 now I got an Exec format error in the error log...

-- update 3
As per this post (http://forums.westhost.com/archive/index.php/t-9858.html) added a symbolic link cgi-bin pointing to /var/www/cgi-bin but still get the same error...

09-02-2008, 12:52 PM
You shouldn't need to add .php to AddHandler. PHP should run anywhere with out any changes to http.conf.

What if anything do you have in /var/www/html-p? Any .htaccess files? You did restart your account, right?

09-02-2008, 12:55 PM
I also did the SSH thing :) so executed php index.php but it quickly returns blank; whereas it works like a charm from subdirs below the main www/html site.

I just noticed this. Are you saying that in SSH the index.php returned blank? If so then do you perhaps have a require in index.php that is pointing to some place that can not be found? Double check other paths to make sure that they are valid. Normally when a php file returns blank it well be a problem with the code itself.

09-02-2008, 07:56 PM
Thanks for the tip!
Fixed that part, now is working from SSH; sadly it still says there's an Exec format error when trying to call it from the browser.
chmod'ed to 755, even though in the main domain it is not needed and it works.
Will remove the .php from AddHandler to see what happens.


Yay, bingo! Works like a charm now.
To wrap up, I put the <directory>... tag and contents inside the <virtualhost>... as a sub-element; and added the symbolic link to cgi-bin as stated above.