GDY
GDY

Reputation: 2961

Simple .htaccess rewrite for single get parameter

How can I rewrite

http://data.example.com/?file=test

to

http://data.example.com/test

via .htaccess?

Upvotes: 2

Views: 160

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

Try:

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /\?file=([^\ &]+)
RewriteRule ^ /%1? [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?file=$1 [L,QSA]

Upvotes: 3

Related Questions