简体   繁体   中英

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

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]

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.

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

;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM