Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
.htaccess 基于htaccess的仅数字URL重定向_.htaccess_Redirect_Url Redirection - Fatal编程技术网

.htaccess 基于htaccess的仅数字URL重定向

.htaccess 基于htaccess的仅数字URL重定向,.htaccess,redirect,url-redirection,.htaccess,Redirect,Url Redirection,让我举例说明-我希望web服务器重定向URL,如http://example.com/-NUM至http://example.com/?p=NUM例如,http://example.com/-121应重定向到http://example.com/?p=121 在这种情况下,.htaccess重定向规则应该是什么样子?模式^-(\d+)$将以连字符匹配数字URI的开头,并捕获到$1中 RewriteEngine On RewriteRule ^-(\d+)$ /?p=$1 [L] 例如,如果这是

让我举例说明-我希望web服务器重定向URL,如
http://example.com/-NUM
http://example.com/?p=NUM
例如,
http://example.com/-121
应重定向到
http://example.com/?p=121

在这种情况下,.htaccess重定向规则应该是什么样子?

模式
^-(\d+)$
将以连字符匹配数字URI的开头,并捕获到
$1

RewriteEngine On
RewriteRule ^-(\d+)$ /?p=$1 [L]
例如,如果这是一个PHP脚本,您可能需要使用
index.PHP
作为目标:

RewriteRule ^-(\d+)$ index.php?p=$1 [L]