简体   繁体   中英

htaccess Url rewrite based on a specific character

Suppose I have a url www.example.com/&page1 I want the url to redirect to www.example. com/getpage.php?redirect=page1 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.

尝试这个:

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

请重新启动apache。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM