.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]