nodejsj
nodejsj

Reputation: 555

htaccess rewrite friendly url

Hello I have the following structure http://localhost/index.php?a=$var1&b=var2&c=$var3

I would like to change it to that when someone goes to http://localhost/$var1/$var2/$var3 they get sent out to http://localhost/index.php?a=$var1&b=var2&c=$var3

Upvotes: 0

Views: 39

Answers (1)

Jon Lin
Jon Lin

Reputation: 143846

Add this at the appropriate place to the htaccess file in your document root.

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+index\.php\?a=([^&]+)&b=([^&]+)&c=([^&\ ]+)
RewriteRule ^ /%1/%2/%3? [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /index.php?a=$1&b=$2&c=$3 [L,QSA]

Note that you're changing the relative URI base when you have the browser load a /aaa/bbb/ccc url as opposed to /index.php. So your links need to either be absolute URL's or you need a base tag in your page headers:

<base href="/" />

Upvotes: 1

Related Questions