Mod_rewrite

admin

Administrator
Staff member
Hi, I'm trying to make a rule on an .htaccess file, but for some reason the rule is not working. First the rule is:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine On<br />RewriteRule ^test/(.*)/(.*).php /test.php?var1=$1&var2=$2<!--c2--></div><!--ec2--><br /><br />The script is called test.php and it is:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />echo "var1 is: ";<br />echo $_GET['var1'];<br />echo "<br />";<br /><br />echo "var2 is: ";<br />echo $_GET['var2'];<br /><br />?><!--c2--></div><!--ec2--><br /><br />I chmod the .htaccess to 644 (-rw-r--r--) because some tutorial on the web suggested it. The .htaccess file is in a subdirectory. Does it have to be in the home directory? The htaccess file and the test.php and in the same directory and when I call the the file I call it relative to where the .htaccess file is.<br /><br />I'm confused. Can anyone help?<br /><br />Thanks,<br />Sandro<!--content-->
Ok, so I got it to work by changing the directory and adding [R] to the end, but now the url changes to the old format. I would like the url to stay like /test/thisis/atest.php instead of /test.php?var1=thisis&var2=atest<br /><br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine On<br />RewriteRule ^test/(.*)/(.*).php /polidiggs/testbed/test.php?var1=$1&var2=$2 [R]<!--c2--></div><!--ec2--><!--content-->
Sometimes you figure things out after you ask people questions. This is one of those times. I needed to add the [L] flag instead of the [R] flag.<br /><br />Sandro<!--content-->
Glad you got it working Sandro<!--content-->
<img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/clapping.gif" style="vertical-align:middle" emoid=":clapping:" border="0" alt="clapping.gif" /> Thanks for the update.<!--content-->
 
Back
Top