0

What.htaccess code should I write to turn something like

localhost/article.php?id=something&number=something 

into just

localhost/article/id

Thoughts guys?

1
  • First show us some code you've already tried Commented Feb 17, 2014 at 12:20

1 Answer 1

1

You can use rules like this in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+article\.php\?id=([^\s&]+) [NC]
RewriteRule ^ article/%1? [R=302,L]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/([^/]+)/?$ article.php?id=$1 [L,QSA,NC]
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, I meant to ask how to change that to localhost/article/id
When I try to visit localhost/article.php?id=something&number=10 the redirection is not working for some reason.
Nevermind, it worked! Only problem I have now is that when I hover over the link, the real link shows. Any way to change that?
hover link cannot be changed by rewrite rule but after you click it can be changed. Its better to change your HTML accordingly with pretty URLs

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.