Mod_rewrite rules in httpd.conf

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Mod_rewrite rules in httpd.conf

Post by RobertGonzalez »

What is needed to place your rewrite rules inside the httpd.conf file? I cannot get this thing to work and I am frustrated beyond all get out. I have tried a number things I found on google, and none of it appears to work. Here is what I have in my httpd.conf now: (note, this is for a virtual site on our network)

Code: Select all

<VirtualHost *:80>
    DocumentRoot /path/to/vhost/root
    ServerName vhost.domain.com
  <Directory /path/to/vhost/root>
    AllowOverride All
      <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^.*$ - [S=2]
        RewriteRule ^/([A-Za-z0-9-_]+)/APPNAME-VISIT-ID-([A-Za-z0-9]+)/?$ /index.php?p=$1&sid=$2 [L]
        RewriteRule ^/([A-Za-z0-9-_]+)/?$ /index.php?p=$1 [L]
      </IfModule>
  </Directory>
</VirtualHost>
Are there other changes to make in the configuration file in order to get this to work properly?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Can you give us an indication as to what you're looking to rewrite? The block you showed there looks fine. But is mod_rewrite definitely available?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The mod_rewrite module is in the modules directory, the LoadModule line is not commented in httpd.conf. What I am after is to push all URLS in the form mydomain.com/page_name to mydomain.com?p=page_name.

I have restarted apache after every change made to the conf file, but it doesn't appear to be taking effect.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Are you positive the rules work? What happens when you put them in an .htaccess file in the web root?

What about the like: Option +FollowSymlinks? I've got .htaccess files with & without that line & they both seem to work. Looking online though I see lots of places that state you need that in your .htaccess file for it to work.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The rules are working locally with a small change to the rewritten file location (instead of /index.php it is /appname/index.php locally).
Post Reply