Forum Moderators: phranque
Well I finalyl have my webserver running with Apache2, MySQL and PHP. I am looking to rebuild my site with the mod_rewrite function. Now considering I have root access I don't want to use a .htaccess file but I want to use the httpd.conf file. I have heard this is the best way to go about it if you have root access.
For some reason though I am having a hard time getting the hang of this. I can do it in a .htaccess fil with no problems. How would I add these features to my httpd.conf file? I have the LoadModule there and my phpinfo() shows teh module is working but I am confused about where to put it in the httpd.conf file. I currently have this code there:
<Directory /website>
RewriteEngine on
RewriteRule ^([0-9A-Za-z]+).html $1.php
Options FollowSymLinks
AllowOverride None
</Directory>
This unfortunatly does nothing. Now I read somewhere that I should add a line AddModule mod_rewrite.c. Is this true? I didn't notice this anywhere in the httpd.conf file even though this tutorial said it would be there and commented with the "#". Do I need to do this because I can't find any AddModules's in my httpd.conf file. Now I am running Apache 2.0 so was this taken out with this version?
Can anyone shed some light on this problem I am having?
Thanks :)
Wes
RewriteRule in httpd.conf behaves slightly differently than in .htaccess. The local URL-path seen by RewriteRule in an .htaccess per-directory context is stripped of the leading slash, because it is localized to the directory where the .htaccess code resides. In httpd.conf, the slash will be present, and so must be matched in your RewriteRule pattern.
So, you'll need to change your rule slightly:
RewriteRule [b]^/([/b][0-9A-Za-z]+).html $1.php
My problem was solved by adding the code to the httpd.include file instead. This file is found at \home\httpd\vhosts\website\conf
I'm not much of an expert, mostly trial and error, and a lot of server restarts.
You may want to review the syntax for the Options directive, and also review the settings for AllowOverride. Both are documented in Apache core [httpd.apache.org]. With AllowOverride set to none, Options won't work. and if the only option you set is FollowSymLinks, you're likely to break other features as well.
Jim
It seems to be working now, but still not 100%.
I have this in my httpd.conf:
<Directory />
Options FollowSymLinks
AllowOverride None
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php
RewriteRule /products/(.*)/index\.html listing.php?category_url=$1
</Directory>
So the first part works fine. It will change any .html to .php. The last one doesn't work correctly. It will take me to /products/xyz/index.html but for some reason when I call the category_url it says its value is /products/xyz/index.html and not xyz like it should. Can anyone tell me why?
Thanks!
Wes