.htaccess rewrite url with get parameter

26,580

The "10" or the id, isn't part of the URL:

example.com/account/blitzen12

So you can't rewrite it into another URL, can't pull it out of thin air. You'll either need to just serve the page without an "id" (and pull it out of the database using the "name") or embed it in the URL without the query string, something like:

example.com/account/10/blitzen12

then you'd be able to rewrite it using:

Options +FollowSymLinks  
RewriteEngine On 

RewriteRule ^account/([0-9]+)/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]
Share:
26,580
blitzen12
Author by

blitzen12

Updated on April 04, 2020

Comments

  • blitzen12
    blitzen12 about 4 years

    this is my first time to try .htaccess

    this is what i want.

    example.com/account/blitzen12 -> example.com/account/index.php?id=10&name=blitzen12
    

    i don't want to include the id in rewriting, is it possible?

    Note: id and name which is 10 and blitzen12 is retrive from the database.
    

    so far this is what I've tried but it didn't work.

    Options +FollowSymLinks  
    RewriteEngine On 
    
    RewriteRule ^account/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]
    

    html code.

    <a href="account/index.php?id=10&name=blitzen12">blitzen12</a>
    

    can anyone help me with this? Thank you.

  • blitzen12
    blitzen12 about 10 years
    I tried what you mention above but it didnt work. for reference i'll edit and include html as well..
  • blitzen12
    blitzen12 about 10 years
    is it possible to rewrite html responses? i'm not sure if it's called outbound rule?
  • CBroe
    CBroe about 10 years
    @blitzen12: mod_rewrite works on requests reaching the server; it has nothing whatsoever to do with HTML. If you want your link URLs in your HTML to be of a specific form, then you have to see to it that they are of that form.