url rewriting in php



I have one more doubt in apache mod_rewrite. I want to rewrite the url mydomain/index.php?category=1&id=1 To mydomain/index/category/1/id/1 How I write rule in .htaccess

And what is the link that i have to give inside the a tag

Please give me a solution..


Not tested, but worth a shot:

RewriteEngine On RewriteRule ^index/category/([0-9]+)/id/([0-9]+)$ index.php?category=$1&id=$2

Your URLs can look exactly like the way you mentioned:

Category 1 <a href="index/category/1/id/1">Product 1</a> <a href="index/category/1/id/2">Product 2</a> Category 2 <a href="index/category/2/id/3">Product 3</a> <a href="index/category/2/id/4">Product 4</a>


Inside the <a> tags you will use the nice link, that is category/1/id/1 (that's exactly why you're using mod_rewrite, to be able to use nice URLs!)

As for the rule, try something like (untested):

RewriteRule category/(.*)/id/(.*)$ index.php?category=$1&id=$2&%{QUERY_STRING} [L]

Actually I would rather use

RewriteRule (.*)/(.*)$ index.php?category=$1&id=$2&%{QUERY_STRING} [L]

So you can call directly mydomain/1/1 but you got the idea I hope

<strong>EDIT</strong>: the &%{QUERY_STRING} part is not necessary for what you asked, but I generally include it in case I want to pass any extra parameter to the page.


  • .htaccess issue to force SSL
  • Remove .html from url in apache2
  • Apache - how to make http requests into https only? [duplicate]
  • htaccess directoryindex redirect looking for css wrong place
  • Convert path to one get variable
  • How to redirect in url by using .htaccess in php?
  • Is this .htaccess section correct?
  • .htaccess - How do you do this? http://www.example.com/domain.com
  • url rewriting in php
  • Removing string from URL using .htaccess
  • Change Displayed URL Structure using mod_rewrite NOT Working
  • Apache mod_rewrite with multiple parameters
  • Redirect subfolder to root domain
  • Simple mod_rewrite problem
  • clean url using mod_rewirte
  • Apache RewriteRule .* index.php [NC,L] Not working
  • Redirect using username in URL with .htaccess [closed]
  • CodeIgniter and htaccess - Protect a specific controller and its methods via AuthType?
  • Retina 4 2x is never used for iPhone 5 simulator in Xcode 6.2 image asset
  • strptime in Javascript
  • Substitute partial line in vim using only substitute command
  • Smart URL with optional parameters?
  • Removing the .php file extension from the URL Request
  • Zeromq with python hangs if connecting to invalid socket
  • F#: In which memory area is the continuation stored: stack or heap?
  • Apache RewriteRule redirection with url encoded
  • Webgrid not refreshing after delete MVC
  • Jquery UI tool tip close icon
  • Linq Objects Group By & Sum
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Optimizing database types to compact database (SQLite)
  • How to add date and time under each post in guestbook in google app engine
  • htaccess rewriting URLs with multiple forward slashes
  • Traverse Array and Display in markup
  • Buffer size for converting unsigned long to string
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • coudnt use logback because of log4j
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory