简体   繁体   English

htaccess基于特定字符的网址重写

[英]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/&page1我希望该网址重定向到www.example. com/getpage.php?redirect=page1 www.example. com/getpage.php?redirect=page1 . www.example. com/getpage.php?redirect=page1 How can I achieve the above using htaccess? 如何使用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. 基本上,我只是想后得到了这个词& url中,如果&存在于URL,然后我想寄作为GET参数getpage.php。

getpage.php handles the value in $_GET['redirect'] and displays the page accordingly. getpage.php处理$_GET['redirect']并相应显示页面。

尝试这个:

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. 您的问题实际上并未指出URL,或者规则必须是动态的,因为您仅举了一个例子。 However this should work. 但是,这应该工作。

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

请重新启动apache。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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