문제

Let me explain by example — I want the web server to redirect a URL like http://example.com/-NUM to http://example.com/?p=NUM i.e. for instance, http://example.com/-121 should be redirected to http://example.com/?p=121.

In this case, what should the .htaccess redirection rules look like?

도움이 되었습니까?

해결책

The pattern ^-(\d+)$ will match numeric URI's beginning with a hyphen and capture into $1.

RewriteEngine On
RewriteRule ^-(\d+)$ /?p=$1 [L]

If this is a PHP script, for example, you may need to use index.php as the target:

RewriteRule ^-(\d+)$ index.php?p=$1 [L]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top