发出将查询字符串重定向到路径的问题

时间:2019-02-15 16:14:24

标签: apache .htaccess redirect mod-rewrite

我想将get查询参数重定向到路径,并保持在代码中使用GET参数的能力。

我很难找到不包含文件扩展名的示例,所以也许这就是给我扔的东西。

我尝试了以下代码,但没有从中得到预期的结果?

RewriteCond %{REQUEST_URI}  ^/spares/$
RewriteCond %{QUERY_STRING} pid=([0-9]*)$
RewriteRule ^(.*)$ /spares/%1 [R=302,L]

例如:

mysite.com/spares/?pid=x

mysite.com/spares/x

编辑: / dev /子目录中的.htaccess副本。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dev/index.php [L]
</IfModule>

RewriteEngine On

# To externally redirect with pid
RewriteCond %{THE_REQUEST} \s+spares/\?pid=(.*)\s [NC]
RewriteRule ^ /spares/%1 [R=301,L,NE]

# To internally rewrite to ?pid=
RewriteCond %{QUERY_STRING} pid=(.+)$
RewriteRule ^dev/spares/$ /dev/spares/?pid=%1 [NC,L]

# END WordPress

1 个答案:

答案 0 :(得分:0)

尝试:

connection.Open();
            SqlCommand commandLogin = new SqlCommand("select * from Proprietário", connection);
            SqlDataReader reader = commandLogin.ExecuteReader();

            while (reader.Read())
            {
                if (reader.GetValue(5).ToString() == txtUser.Text && reader.GetValue(6).ToString() == txtPass.Text)
                {
                    User = txtUser.Text;
                    tipo = reader.GetBoolean(7);
                    tssl_Login.Text = "Login feito com sucessso!";
                    break;
                }
            }