Javed Shaik
Javed Shaik

Reputation: 29

Dynamic URL redirect

How to redirect my url - www.example.com/home.php?rid=888601032

to www.example.com/examplepage.php

i have tried several htaccess codes 7 Im new to htccess, I would appreciate if someone can give me the correct redirect code.

Upvotes: 2

Views: 543

Answers (4)

g1smd
g1smd

Reputation: 76

The redirect you need is incredibly simple.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(home\.php)?\?rid=888601032\ HTTP/
RewriteRule ^(home\.php)?$ http://www.example.com/examplepage.php? [R=301,L]

It redirects any root request with the RID within it.

Upvotes: 1

Dalmas
Dalmas

Reputation: 26557

Wouldn't be better to use php to do this?

if ((int)$_GET['rid'] == 888601032) // or something like this
    header('Location: examplepage.php');

It depends on what you want to do, but it would be more flexible if you want to redirect to a different page depending on the "rid" parameter, or if you want to do some operation (like setting a cookie) before redirecting the user.

Upvotes: 0

aorcsik
aorcsik

Reputation: 15552

Put this in yout .htaccess file:

RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} rid=888601032
RewriteRule ^home.php       examplepage.php [R,L,QSA]

If you dont want the redirect to be visible, leave the [R] flag.

Hope this helps!

Upvotes: 1

ayush
ayush

Reputation: 14588

The syntax is:

redirect accessed-file URL-to-go-to

There are 3 parts;

(1) the Redirect command,
(2) the location of the file/directory you want redirected, and
(3) the full URL of the location you want that request sent to.

These parts are separated by a single space and should be on one line.

For example, if you want to redirect users from oldfile.html in the www directory of your account, myaccount, to newpage.html, the syntax should be

redirect /~myaccount/oldfile.html http://www.indiana.edu/~myaccount/newpage.html

Upvotes: 1

Related Questions