Page 1 of 1

Mod_rewrite rules in httpd.conf

Posted: Tue Nov 21, 2006 1:59 pm
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?

Posted: Tue Nov 21, 2006 2:52 pm
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?

Posted: Tue Nov 21, 2006 3:24 pm
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.

Posted: Wed Nov 22, 2006 10:17 am
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.

Posted: Wed Nov 22, 2006 10:30 am
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).