1

My url looks like -
http://localhost/user_notes/public/index.php?id=1234.
I want to be turn it into user friendly url like
http://localhost/user_notes/public/1234

My .htaccess file looks like -

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^/([0-9]+)/ /index.php?id=$1
</IfModule>

So now when I use http://localhost/user_notes/public/1234 location in browser it is giving me error (The requested URL was not found on this server). So above htaccess file is not working as I expected.

My directory structure given below -

enter image description here

1 Answer 1

3

With your shown samples, please try following. Please make sure you clear your browser cache before testing your URLs.

<IfModule mod_rewrite.c>
  RewriteEngine ON
  RewriteBase user_notes/public/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([0-9]+)/?$ index.php?id=$1
</IfModule>
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for helping me again. (+_+)
@Abhishekkamal, your welcome cheers and happy learning
If I use #1234 (ID with the hash) then it is not giving me the ID by echo $_GET['id'] (because regex is currently searching for numbers as ID). So what should be solution for this problem ?
@Abhishekkamal, oh ok, actually I had picked it up from your question :) not an issue try something like RewriteRule ^([#]?[0-9]+)/?$ index.php?id=$1 it should work fine cheers.
nope I am still not getting id with $_GET['id'] I think because browsers has some default behaviour if he finds # in URL parameter
|

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.