Michał Bereszyński
Michał Bereszyński

Reputation: 49

.htaccess PHP rewrite link

I have problem and dont have any idea how to solve it. I have URL like this: http://somedomain.com/link.php?lnk=1&sid=dsds

and need to change it to this:

http://somedomain.com/link/1/dsds

If there is only one variable I use this:

RewriteEngine on RewriteRule ^link/([a-zA-Z0-9_-]+)$ link.php?lnk=$1

But I don't have any idea how to attach that second variable &sid={something}

Thanks in advance for any help.

Upvotes: 1

Views: 98

Answers (3)

hpelleti
hpelleti

Reputation: 342

Try this:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^lnk=(.+)\&sid=(.+)
RewriteRule ^link\.php link/%1/%2/?  [R=301,L]

Upvotes: 0

Dmytro Dzyubak
Dmytro Dzyubak

Reputation: 1642

if the first parameter/value uses digits only, then you can use

RewriteEngine On    
RewriteRule ^link/([0-9]+)/([a-zA-Z0-9_-]+)$ link.php?lnk=$1&sid=$2 [L]

Apache mod_rewrite Introduction (see "Figure 1" in "Regex Back-Reference Availability" section)

RewriteRule Flags

Upvotes: 1

Ray
Ray

Reputation: 41448

 RewriteEngine on 
 RewriteRule ^link/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ link.php?lnk=$1&sid=$2

Upvotes: 3

Related Questions