Forum Moderators: phranque

Message Too Old, No Replies

search engine friendly URL's and mod_rewrite

getting mod_rewrite to work on a default apache configuration

         

grahowler

10:38 pm on May 18, 2003 (gmt 0)



Hi Folks

This is about trying to achieve search engine friendly URL's on a development machine with PHP/Apache on Win2K. When searching the subject I found some great posts here at webmasterworld, I got it working in the end but I still have a couple of questions. Sorry for the long winded post but I thought I should explain what I encountered in case it helps anyone in the future.

I started with this article: [evolt.org...] One of the user comments suggests using mod_rewrite to achieve the objective, and that seemed the most practical approach so I began to look into that. I also found a good article on that here: [sitepoint.com...]

I have Apache installed in: C:\apache
The Root directory is: C:\apache\htdocs
I was working from: C:\apache\htdocs\test
Trying to get a URL: http://myserver/test/articles/123
To translate to: http://myserver/test/articles.php?id=123

Putting this into action, though, proved a bit tricky. What was immediately obvious was that I needed to modify httpd.conf and create a .htaccess file. So I did the following.

1. Uncommented the httpd.conf lines...

#LoadModule rewrite_module modules/mod_rewrite.so
#AddModule mod_rewrite.c

2. Created a .htaccess file in C:\apache\htdocs\test with...

Options FollowSymlinks
RewriteBase /test/
RewriteEngine on

RewriteRule ^articles/([0-9]+) articles.php?id=$1

3. Restarted Apache and guess what? IT DIDN'T WORK! It produced the following error in error.log...

Premature end of script headers: c:/php/php.exe

What wasn't immediately obvious to me was that I needed to change an Apache Directive AllowOverride, for the directory where I wanted to use .htaccess, from None to All. That is simple enough except I tried to get it to work adding this to httpd.conf...

<Directory /test>
Options FollowSymLinks
AllowOverride All
</Directory>

I tried several different combinations, including <Directory /> and <Directory /test/>, but it wasn't until I used the full path to the directory that it worked...

<Directory "C:/apache/htdocs/test">
Options FollowSymLinks
AllowOverride All
</Directory>

My understanding of how httpd.conf works might be wrong but isn't <Directory /> meant to be the same as <Directory "C:/apache/htdocs">?

Also, when I view http://myserver/test/articles/123 the links to files in sub directories produces an error...

File does not exist: c:/apache/htdocs/test/articles/images/img1.gif

This is correct. The directory c:/apache/htdocs/test/articles/images doesn't exist. It should be c:/apache/htdocs/test/images.

The image reference in articles.php would be <img src="images/img1.gif">.

Obviously the articles/ part of the URL is being appended to the source reference but I am unsure about how to remedy this. Any ideas?

thx in advance.

jeremy goodrich

6:43 pm on May 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hm, I know more than a bit about apache, but apache on winders? Perhaps another bloke can give a shot at helping out with this one?