leonglass Posted October 4, 2007 Share Posted October 4, 2007 I seem to be having a problem understanding how mod_rewrite is supposed to work. I have searched this board but can't seem to answer my question so here goes. I want to implement clean urls so I have planned to rewrite http://localhost/gamvc/users into http://localhost/gamvc/index.php?module=users but seem to be unable to make it work. I am working with Apache 2.2.6 on a Linux box where the public dir is /var/www/localhost/htdocs/ and my test site is in a sub dir of that named gamvc. In the dir gamvc I have the file index.php and a .htaccess file the contents of which are: RewriteEngine On RewriteRule ^gamvc/([alpha]+) gamvc/index.php?module=$1 [L] My htaccess file is definitely being accessed as I have verified this by causing internal server errors by placing an invalid directive in it. The contents of the index.php file are print "{$_SERVER['REQUEST_URI']} <br />"; print "<a href='http://localhost/gamvc/users'>A Link</a>"; which gives me a web page displaying /gamvc/index.php A Link but always generates The requested URL /gamvc/users was not found on this server. when I click the link. I have tried adding RewriteBase / and /gamvc as directed in most of the posts I found here. I have also had the rule starting ^/?gamvc to try and account for the leading slash but my understanding is that this should not be required on a 2.x server. As far as my limited understanding goes the above rule should check for one or more alpabetical characters after gamvc/ and store it in the $1 atom. This atom should then be appended after the = sign in the target part. Can anybody point out where my understanding has gone wrong. Thanks. Quote Link to comment Share on other sites More sharing options...
leonglass Posted October 4, 2007 Author Share Posted October 4, 2007 RewriteEngine On RewriteBase /gamvc RewriteRule ^([^/]+) index.php?module=$1 [PT] This sorted it out. Does anyone know why my character class didn't work. [alpha] didn't match and [:alpha:] caused an internal server error. Quote Link to comment Share on other sites More sharing options...
leonglass Posted October 4, 2007 Author Share Posted October 4, 2007 This now puts index.php into $_GET['module'] so it must be looping back and rematching. I changed the flag to [L] but this did not change it. I can also remove RewriteBase /gamvc and it still works. Looks like I still need some help. ??? Quote Link to comment Share on other sites More sharing options...
hackerkts Posted October 6, 2007 Share Posted October 6, 2007 Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)/([a-zA-Z0-9]+)$ $1/index.php?module=$2 Not sure if it works, but give it a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.