Jump to content

problem understanding rewrite


leonglass

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.