Hi I want to use mod_rewrite with .htaccess file to clean up my URLs so that for example, this: www.mysite.com/artist.php?cid=12&aid=56 displays as this: www.mysite.com/artist/12/56 I have enabled LoadModule rewrite_module modules/mod_rewrite.so in my httpd.conf file and placed the .htaccess file in the site root. The .htaccess file contains this: RewriteEngine On RewriteRule ^artist/(.*)/(.*)/ /artist.php?cid=$1&aid=$2 I have full control of my development server but no control over production server. When I try to load www.mysite.com/artist/12/56 I get a Not Found error: 'The requested URL /bigartweb/artist/12/56 was not found on this server.' Am very new to Apache so any help much appreciated. Jonathan Attree
Try putting this "RewriteBase /" under RewriteEngine on.. like this; RewriteEngine on RewriteBase / I had the same issue a little while back and this seemed to fix it.
Thanks for the reply. Had already tried that in the meantime. My .htaccess file now looks like this but still doesn't seem to work: Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^artist/(.*)/(.*)/ /artist.php?cid=$1&aid=$2 [L] Am using Apache 2.2 on WinXP Pro and my site root is at: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\bigartweb
Where are the pages going now? Try... RewriteRule ^artist/(.*)/(.*)$ /artist.php?cid=$1&aid=$2 [L] or RewriteRule ^artist/(.*)/(.*)/$ /artist.php?cid=$1&aid=$2 [L]
Sorry, neither of those work either. I currently have only two pages: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\bigartweb\index.php and C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\bigartweb\artist.php I'm trying to call artist.php from index.php. If I change the rule to this: RewriteRule ^artist.php /test.php [L] It should redirect artist.php to test.php, yes? This doesn't work either so maybe mod_rewrite is not working at all? Thanks again Jonathan Attree
The rule should be: RewriteEngine on RewriteRule ^artist/([^/]*)/([^/]*)/$ artist.php?cid=$1&aid=$2 Code (markup): However the URL must be www.mysite.com/artist/12/56/ note the trailing / www.mysite.com/artist/12/56 will not match the rule, if you want either to work then use: RewriteEngine on RewriteRule ^artist/([^/]*)/([^/]*)/?$ artist.php?cid=$1&aid=$2 Code (markup): If that doesn't work then check that mod_rewrite is loading. I don't ever run Apache on Windows so am just assuming it works the same as on Linux.
Thanks for reply. This now works and passes correct values to called page: Options +Indexes Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule ^artist/([^/]*)/([^/]*)/$ artist.php?cid=$1&aid=$2 However now all relative links to images, stylesheets etc fail on called page. If I call mysite.com/artist/12/34/ this translates ok to mysite.com/artist.php?cid=12&aid=34 but a link back to index.php from artist.php then appears in the status bar as: mysite.com/artist/12/34/index.php. Any more help please? Thanks in advance. Jonathan Attree
In the <head> area add <base href="http://www.yourdomain.com/" /> changing that to be the absolute path to your site.
Thanks tolra, it now works OK. Only problem left is that I now have to change the <base> tag every time I upload files from testing to live server. No way around that I suppose? Thanks again.