tags:

views:

21

answers:

2

I took a look around at other mod_rewrite questions and couldnt come up with an answer, so if anyone would point me to one that I may be duplicating I would appreciate it.

Anyways my question is: Why is my mod rewrite not working? I followed like 3 tutorials and spent a while reading forums and previous questions on this site, and couldnt get any of them to work. Ive tried doing it through my vhosts.conf file (I think its also known as the httpd.conf on some installations of linux) and through a .htaccess

Here is my .htaccess filed code

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteBase /

RewriteRule ^/article/([0-9]+)$ article.php?art_id=$1 [NC,L]

Here is the link im trying to get working: mysite.com/article?art_id=$1

To be honest I only have a slight clue as to how mod_rewrite works.

I have mod_rewrite installed (I don't manage the server, but the company I work for also has hosting services, thats how I have access to the vhosts.conf but I did not set the server up, and as far as I know the guy doing it is pro and set it up right)

I put this in to see if I could get it to work and it redirected me to my home page (I think that means its working)

# Options +FollowSymLinks 
RewriteEngine on 
RewriteRule ^fakepage\.html$ http://yoursite.com/ [R,L]
+1  A: 

At least as far as your .htaccess file goes, using the rule you have will not work because the input to the RewriteRule will never have an initial forward slash on it. The rule should instead look more like this:

RewriteRule ^article/([0-9]+)$ article.php?art_id=$1 [NC,L]

However, what you have should have worked when you tried it in a virtual host (assuming you restarted the server), so I'm not sure if this is the actual issue. In what way is the rewrite not working? Are you getting 404 errors instead of being redirected to the file you were expecting?

Tim Stone
I must have messed something up when I had it in my vhosts.conf and didn't notice, but the url were broken so it wasn't working until I removed that slash
Latency
A: 

Tim is correct about the slash at the beginning of your RewriteRule.

When trying to figure out Rewrites, it can be helpful to turn on logging:

RewriteLog "/var/www/mysite.com/rewrite.log"
RewriteLogLevel 9
enobrev