PHP htaccess多个变量

时间:2016-05-12 05:55:38

标签: php .htaccess

您好我正在使用以下htaccess。

<title>Floating Divs</title>
<h1>Floating Divs</h1>
<div>
  <div id="p1">DIV</div>
  <div id="p2">DIVDIVDIV</div>
</div>

在第一条规则中,我传递了一个变量。它工作正常。但在第二条规则中,我传递了两个变量。但是它重定向到第一个规则。 请帮我解决这个问题。

我传递的第一个网址是:RewriteEngine On RewriteBase /JustSnacksNew/ RewriteCond %{THE_REQUEST} /Products\.php\?category=([^\s&]+) [NC] RewriteRule ^ %1? [R=302,L] RewriteCond %{THE_REQUEST} /Products\?category=([^\s&]+) [NC] RewriteRule ^ %1? [R=302,L] RewriteRule ^([A-Z,0-9,a-z-]+)$ Products.php?category=$1 [L,NC,QSA] RewriteCond %{THE_REQUEST} /ViewProduct\.php\?category=([^\s&]+)&product=([^\s&]+) [NC] RewriteRule ^ %1? [R=302,L] RewriteCond %{THE_REQUEST} /ViewProduct\?category=([^\s&]+)&product=([^\s&]+) [NC] RewriteRule ^ %1? [R=302,L] RewriteRule ^([A-Z,0-9,a-z-]+)$ ViewProduct.php?category=([^\s&]+)&product=$1 [L,NC,QSA] # PHP hiding rule RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [L]

第二个网址传递是:./Products.php?category=catname

1 个答案:

答案 0 :(得分:0)

您可以使用:

RewriteEngine On
RewriteBase /JustSnacksNew/

RewriteCond %{THE_REQUEST} /ViewProduct(?:\.php)?\?category=([^&]+)&product=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=302,L]
RewriteCond %{THE_REQUEST} /Products(?:\.php)?\?category=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# PHP hiding rule
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^([A-Z,0-9-]+)/?$ Products.php?category=$1 [L,NC,QSA]
RewriteRule ^([A-Z,0-9-]+)/([A-Z,0-9-]+)/?$ ViewProduct.php?category=$1&product=$2 [L,NC,QSA]