使用htaccess将新参数添加到现有URL

时间:2017-06-21 06:31:15

标签: php apache .htaccess redirect mod-rewrite

我有一个类似下面的网址

http://filespecification.phpnet.us/index3.php

但我想在此网址中添加一个额外的参数,如下所示。

http://filespecification.phpnet.us/index3.php?email=

为此,我使用.htaccess重定向其他参数,但它没有重定向仍显示原始网址。

RewriteRule /index3.php$ index3.php?email=$1 [R]

但它不起作用。如何使用其他参数重定向?

2 个答案:

答案 0 :(得分:1)

试试这个简单的。希望这会有所帮助。我测试了它。

  

1。 QUERY_STRING不包含电子邮件。

     

2。如果请求uri index3.php重定向到/index3.php?email=somevalue

<强>标志:

  

R用于重定向。

     

L上次重定向。

     

QSA查询字符串追加

RewriteEngine on
RewriteCond %{QUERY_STRING} ^(?!email)
RewriteRule index3.php$ /index3.php?email=somevalue [L,R,QSA]

您可以在此http://htaccess.mwl.be/

查看此.htaccess代码

答案 1 :(得分:0)

由于领先的斜杠,您的规则不起作用。你需要删除它。

RewriteCond %{THE_REQUEST} !\?email= [NC]
RewriteRule index3.php$ /index3.php?email=mail [L,R]