0

What rewrite rule in .htaccess do I need to rewrite an url in the form

http://localhost:8080/test/college_details.php?id=[some id]&name=[some name]

to the form

http://localhost:8080/test/[some name]/[some id]

For example, I'd like the URL http://localhost:8080/test/college_details.php?id=53&name=college-name to be rewritten to http://localhost:8080/test/college-name/53

Martijn
  • 11,964
  • 12
  • 50
  • 96
Renjitha22
  • 213
  • 1
  • 7
  • 22
  • 1
    try to find a Solution on your own and then show us what you tried so far – Ann-Sophie Angermüller Mar 27 '17 at 09:14
  • RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^m3/([a-zA-Z0-9-]+)$ m3/college_details.php?name=com_frontpage&id=$1 [L,QSA] but its not working! – Renjitha22 Mar 27 '17 at 09:15
  • http://stackoverflow.com/questions/16388959/url-rewriting-with-php – user3386779 Mar 27 '17 at 09:16
  • Possible duplicate of [URL rewriting with PHP](http://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Imran Saeed Mar 27 '17 at 10:26
  • Welcome to Stack Overflow! I edited your question to have a clearer title, included some formatting, and included both the original version as the re-written version of both the abstract version of your question with placeholders and the concrete example. Also, I removed the niceties like introductions, and closing sentences. They don't belong on StackOverflow, and questions shouldn't have them – Martijn Mar 27 '17 at 13:51
  • Do you want to redirect `http://localhost:8080/test/college_details.php?id=53&name=college-name` to pretty URL as well? – anubhava Mar 27 '17 at 19:41

1 Answers1

1

Use below rule in test directory.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\d]+)$ college_details.php?id=$2&name=$1 [QSA,L]
Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45