重写动态 url 结构

Rewrite dynamic url structure

大家好,我有一些带有人名的页面。我想将它们移动到子文件夹中,但不知何故将旧页面重定向到新页面,所以当访问者检查旧页面以将它们重定向到新页面时,但我想从 url结构。

http://domain.com/john-p001/       -> http://domain.com/person/john/

http://domain.com/george-p002/     -> http://domain.com/person/george/

我在 .htaccess 上的当前设置中正在做什么

## internal forward from pretty URL to actual one
RewriteRule ^([^/]+)-p([0-9]+)\/$ person.php?name=&id= [L,NC,QSA,NE]

我还有一个问题,这个重定向是否会让我的搜索引擎在这些页面上保持排名?

您可以在 root .htaccess 中使用此规则:

Options -MultiViews
RewriteEngine On
RewriteBase /

# redirect old URLs to newer ones
RewriteRule ^([^-]+)-p([0-9]+)/?$ /person/ [L,NC,R=302]

## internal forward from pretty URL to actual one
RewriteRule ^person/([\w-]+)/?$ person.php?name= [L,NC,QSA]