0

My issue is pretty simple however as I am new to mod_rewrite I seem to be very confused. basically I am trying to make vision friendly urls with mod_rewrite. ie: 'http://example.com/user.php?id=3' works the same as 'user/7854' etc. i currently have a regex rule as so:

RewriteEngine on 
RewriteRule ^user/([a-z]+)/?$ user.php?id=$1  

phpinfo() confirms that mod_rewrite is in fact operating/working. My understanding of this is that, if the user is directed to 'http://example.com/user/7854' (for example) The mod_rewrite regex will translate via apache to my php script: 'http://example.com/user.php?id=7854' because anything after 'user/' becomes captured. That being said, this is my user.php:

<?php
    echo $_GET['id'];
?>

now as you can imagine 'http://example.com/user.php?id=7854' displays 7854 however 'http://example.com/user/7854' gives me an error (404) why is this? what have i misunderstood? I've spent an hour on numerous forums just to get this far, this concept isnt coming easy to me at all. cheers to any help.

2 Answers 2

2

Like @andrea.r says: you have rule for all characters but no numbers.

Change: RewriteRule ^user/([a-z]+)/$ user.php?id=$1

to: RewriteRule ^user/([a-z,0-9]+)/$ user.php?id=$1

Sign up to request clarification or add additional context in comments.

Comments

0

User ID is numerical and you've written [a-z] instead of [0-9].

Try this: RewriteRule ^user/([0-9]+)/?$ /user.php?id=$1

2 Comments

EDIT: added backslash before user.php?id=$1
still no dice (404) on that idea, even tried emptying the cache just in case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.