Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何从url中删除数字并使用301重定向_Regex_.htaccess_Redirect_Http Status Code 301 - Fatal编程技术网

Regex 如何从url中删除数字并使用301重定向

Regex 如何从url中删除数字并使用301重定向,regex,.htaccess,redirect,http-status-code-301,Regex,.htaccess,Redirect,Http Status Code 301,我有很多用户配置文件url,希望从url中删除用户id,并使用.htaccess重定向301 例如,我的当前url是,希望以这种方式重定向您可以尝试以下方法: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/(.*)/[\d]+-(.*)$ [NC] RewriteRule .* %1/%2 [R=301,L] 它将永久重定向: http://www.example.com/1084-jerome-smith/

我有很多用户配置文件url,希望从url中删除用户id,并使用.htaccess重定向301 例如,我的当前url是,希望以这种方式重定向

您可以尝试以下方法:

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



将重定向具有以下格式的任何URL:
http://www.example.com/OptionalFolders/NumericID-anything-anything/anyname.php
,其中
NumericID
是本例中要删除的编号
1084

我不熟悉.htaccess,但您能解释一下在{REQUEST\u FILENAME}中传递什么吗-f、 {请求文件名}-d和{REQUEST_URL}。修改了我的答案。请检查它。谢谢:)你的代码工作,但需要你的小帮助,我在这个url中得到两次php想要删除php后,好的。我想我知道为什么。我将修改我的答案。已更新。请再试一次。