monkey_boys
monkey_boys

Reputation: 7348

How to redirect in url by using .htaccess in php?

How to redirect in url by using htaccess in php?

http://www.example.com/randomstring/2

i would like to go to id page 20 thank

Upvotes: 0

Views: 524

Answers (3)

stecb
stecb

Reputation: 14746

You should use mod_rewrite for example in this way:

RewriteEngine On

RewriteRule ^(randomstring)/([0-9]+)$  /randomstring/$1/ [QSA,R] 
RewriteRule ^(randomstring)/([0-9]+)/$ index.php?page=$1&id=$2 [QSA,NC,L]

If you want to simply redirect from a domain to another just write:

RewriteRule ^(randomstring)/([0-9]+)$ http://www.example.com/$1/$2/ [QSA,NC,L,R=301]

Upvotes: 2

thedom
thedom

Reputation: 2518

Copy that into your .htaccess file in the directory you need it:

RewriteEngine On
RewriteRule ([A-Za-z0-9]+)/([0-9]+)$ index.php?id=$2

www.domain.tld/asdf/2 --> index.php?id=2
www.domain.tld/asdfa923als/52 --> index.php?id=52

;-)

Upvotes: 1

Femaref
Femaref

Reputation: 61437

use mod_rewrite, it's a module for apache. You can see the documentation here. .htaccess files control the webserver, not php, so you have to look there.

Upvotes: 1

Related Questions