0

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

3
  • You want to write in address bar http://www.reservationnumbers.com/companydata.php?name=apple and call to http://www.reservationnumbers.com/apple ? Or vice versa ? Commented May 29, 2016 at 7:32
  • No I want reservationnumbers.com/companydata.php?name=apple to redirect reservationnumbers.com/apple Commented May 29, 2016 at 7:37
  • I have tried RewriteEngine On RewriteRule ^([^/d]+)/?$ comapanydata.php?name=$1 [QSA] but it doesnt works Commented May 29, 2016 at 7:39

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

3 Comments

Parameters are dynamic and now its redirects to 404
What url are you going to? this works if you enter /companydata.php?name=apple and redirects to /apple does the uri /apple exist?
@user1831355 if the answer solved your issue, please accept it by clicking the backtick sign.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.