htaccess Url基于特定字符重写

Suppose I have a url www.example.com/&page1 I want the url to redirect to www.example. com/getpage.php?redirect=page1. How can I achieve the above using htaccess?

Basically I just want to get the word after & in the url if & exists in the url then I want to send it as a get parameter to getpage.php.

getpage.php handles the value in $_GET['redirect'] and displays the page accordingly.

Try this:

Redirect 301 /&page1 http://www.example.com/getpage.php?redirect=page1

Your question doesn't actually state the URL or rules need to be dynamic since you only give one example. However this should work.

RewriteEngine On
RewriteRule ^\&(.+)/?$ /getpage.php?redirect=$1 [L]
Redirect 301 /&page1 /getpage.php?redirect=page1

Please restart apache.