如何从网址中删除数字并使用301重定向

时间:2013-01-23 03:59:24

标签: regex .htaccess redirect http-status-code-301

我有很多用户个人资料网址,想要从网址中删除用户ID,并使用.htaccess重定向301 例如,我当前的网址为http://www.example.com/1084-jerome-smith/profile.php,并希望以这种方式重定向http://www.example.com/jerome-smith/profile.php

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  ^/(.*)/[\d]+-(.*)$    [NC]
RewriteRule .*  %1/%2  [R=301,L]

它将永久重定向:

http://www.example.com/1084-jerome-smith/profile.php

要:

http://www.example.com/jerome-smith/profile.php


将使用以下格式重定向任何网址:http://www.example.com/OptionalFolders/NumericID-anything-anything/anyname.php,其中NumericID是在这种情况下要移除的数字1084