如何通过使用的.htaccess在PHP重定向的URL?重定向、htaccess、PHP、URL

2023-09-02 01:10:46 作者:一抹

如何在PHP中使用htaccess的重定向URL中的?

How to redirect in url by using htaccess in php?

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

我想转到ID第20页谢谢

i would like to go to id page 20 thank

推荐答案

您应该以这种方式使用mod_rewrite例如:

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]