user1831355
user1831355

Reputation: 95

How to redirect url using .htaccess

How to redirect url using .htaccess from -

http://www.reservationnumbers.com/companydata.php?name=apple

to

http://www.reservationnumbers.com/apple

OR

http://www.reservationnumbers.com/companydata.php/apple

Upvotes: 0

Views: 70

Answers (1)

Amit Verma
Amit Verma

Reputation: 41209

To redirect /companydata.php?name=apple to /apple you can use the following rule :

RewriteEngine on

RewriteCond %{THE_REQUEST} /companydata\.php\?name=apple [NC]
RewriteRule ^ /apple? [L,R]

If the name permameter is dyanamic, you can use :

RewriteEngine on

RewriteCond %{THE_REQUEST} /companydata\.php\?name=([^\s]+) [NC]
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /companydata.php?name=$1 [L]

Upvotes: 1

Related Questions