mod_rewrite and virtual hosts

tench

Registered
Hi guys.

I am having a serious problem with mod_rewrite on OS 10.3.3 running Apache. Basically, I had a nice set up working on my web hosting provider's server, but I had to replicate the set up on my laptop in order to present it at a meeting, where no internet connection will be available.

I don't get it: the virtual host is set up ok, and the directory index works, i.e. when I go to www.project.dev (which is the name of my virtual host), I get to the right index page (www.project.dev/start.php). But that's also where everything stops working. None of the rewrites seem to take effect and I can't move from the first page without getting "requested url not found" type of message.

Code:
<VirtualHost 127.0.0.1> 
DocumentRoot /Users/psychomachine/Sites/dictionary 
ServerName [url]www.project.dev[/url] 
ServerAlias project.dev 
RewriteEngine on 
<Directory /Users/psychomachine/Sites/dictionary> 
DirectoryIndex start.php 
Options FollowSymLinks ExecCGI MultiViews 
RewriteBase / 
RewriteRule !^start\.php.*$ -[C] 
RewriteRule !^data/.*$ -[C] 
RewriteRule !^data$ -[C] 
RewriteRule ^(.+)$ /start.php/$1 
</Directory> 
</VirtualHost>

If anybody has any idea what could be going wrong here, please let me know. I won't be going to bed for the next two days... :D
 
hi tench...

for mod_rewrite to works, you need to enable it first. As for 10.3, usually it has already being enable. To check, run your phpinfo(); script. You should see the mod_rewrite option.

Next, you need to configure your apache server. Look for AllowOverride section. If not mistaken, you need to set the directory to enable AllowOverride. You can check this in the manual.

Once this has been setup, you must create a file named ".htaccess" and upload to your server where you want to apply the mod_rewrite action.

Your .htaccess file will look like this

RewriteEngine On
RewriteBase /
RewriteRule !^start\.php.*$ -[C]
RewriteRule !^data/.*$ -[C]
RewriteRule !^data$ -[C]
RewriteRule ^(.+)$ /start.php/$1

Hopes this will help you. I have been using the mod_rewrite on our server. Check it out. The mod_rewrite redirect the .html file to .php file.

- www.darkstation.com -
 
Back
Top