views:

40

answers:

2

I am playing with mod_rewrite now, and have successfully enabled it.

However, I need to put a htaccess file inside var/www/ in order to achieve what I want, which is to rename Urls simply... When I place it my website becomes very strange and nothing basically works...

Is there any code I need to put into the htaccess file in order for things to act normally?

Here is the htaccess file I have so far:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/ad\.php
RewriteRule ^(.*)$ ad.php?ad_id=$1 [L]

My DocumentRoot is also set to var/www/ and my entire website root is there... (index.html etc etc)...

What am I missing about the htaccess?

If you need more input let me know...

+1  A: 

This isn't a complete answer but it will give your more information that can help you.

  1. You can put options on the same line Options +FollowSymLinks -Indexes
  2. Not all hosts allow .htaccess, or not all .htaccess commands. This can cause problems and pages not to work.
  3. Try commenting out everything (using # sign in front of each line), then, starting at the top, uncomment until you find the problem line.
Kerry
+2  A: 

I suspect that none of your css files, js or images are loaded. Furthermore, none of your links work either. If so, the problem could be in the RewriteRule cause basically that rule is telling apache to pass all requests to ad.php

You need to fine tune your RewriteRule, so that only the ad links are being affected by the rule.

First, by expanding the RewriteRule like this:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} !^/ad\.php
RewriteRule ^(.*)$ ad.php?ad_id=$1 [L]

These 3 lines that I've added are telling apache to apply the rule only if the requested filename is not a directory, an existing file or a symbolic link - this should take care of the static content, such as the css and images. If your other pages where you're links are pointing at, are also physically on the HDD of the server (plain html or php files), should start working again.

But, as I already said on this question of yours (http://stackoverflow.com/questions/2991396/little-mod-rewrite-problem/2991453#2991453) you need to fine tune that rule, so that only ads are being met by the rule and nothing else.

robertbasic