Little Mod Rewrite help

Kloon

Expert Member
Joined
Nov 6, 2006
Messages
1,670
So I have this in my .htaccess

Code:
RewriteEngine On
RewriteBase /rewrite
RewriteRule ^(.*)$ user.php?id=$1 [L]

and I have a php file
PHP:
<?php
  echo "username is ".$_GET['id'];
?>

so according to me if I visit http://127.0.0.1/rewrite/theusername the php file should return theusername, but instead it returns user.php
 

Kloon

Expert Member
Joined
Nov 6, 2006
Messages
1,670
Got it working fix was
Code:
RewriteEngine On
RewriteBase /rewrite
RewriteRule ^(.*)/$ user.php?id=$1

forgot the /$
 

Kloon

Expert Member
Joined
Nov 6, 2006
Messages
1,670
k finally got it working with the following code, this is what baffles me cause it exactly the same as the first try just a bit strick when it comes to what characters to use.

Code:
RewriteEngine On
RewriteBase /rewrite
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?id=$1
 

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
Yeah, you limit the REGEX there to only allow A - Z (upper and lower case), 0 - 9 a underscore and dash characters. Do you want it to accept all characters?

You could achieve a more lenient rewrite with:

Code:
RewriteEngine On
RewriteBase /rewrite
RewriteRule ^(.*)$ user.php?id=$1
RewriteRule ^(.*)/$ user.php?id=$1

Still got a problem if I go to http://127.0.0.1/rewrite/test/ it works but if I go to http://127.0.0.1/rewrite/test it fails
The second URL failed because the rewritten template explicitly required a "/" after the URL. My recommendation above would cater for both.
 
Last edited:

Kloon

Expert Member
Joined
Nov 6, 2006
Messages
1,670
Yeah, you limit the REGEX there to only allow A - Z (upper and lower case), 0 - 9 a underscore and dash characters. Do you want it to accept all characters?

You could achieve a more lenient rewrite with:

Code:
RewriteEngine On
RewriteBase /rewrite
RewriteRule ^(.*)$ user.php?id=$1
RewriteRule ^(.*)/$ user.php?id=$1

I only want to allow that chars, thing is in my first try I did use RewriteRule ^(.*)$ user.php?id=$1 and it dit not even pick up http://127.0.0.1/rewrite/user
 

Kloon

Expert Member
Joined
Nov 6, 2006
Messages
1,670
Yeah, you limit the REGEX there to only allow A - Z (upper and lower case), 0 - 9 a underscore and dash characters. Do you want it to accept all characters?

You could achieve a more lenient rewrite with:

Code:
RewriteEngine On
RewriteBase /rewrite
RewriteRule ^(.*)$ user.php?id=$1
RewriteRule ^(.*)/$ user.php?id=$1


The second URL failed because the rewritten template explicitly required a "/" after the URL. My recommendation above would cater for both.

No the statements above does not work, it is supose to work acording to my regex knowledge but it doesn't
 
Top