使用两个参数重写URL

时间:2014-07-08 17:40:35

标签: php .htaccess

我无法更改htaccess文件,

目前我在从htaccess重写后显示这样的页面:

www.domain.com/contact

在从htaccess重写之前成为这个url:

www.domain.com/index.php?show=contact

我正在使用此代码进行重写:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]

    RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?show=([^\s&]+) [NC]
    RewriteRule ^ /%1? [R=302,L]

    Header set X-UA-Compatible "IE=Edge,chrome=1"


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?show=$1 [L,QSA]

我现在要做的是设置两个参数,例如:

www.domain.com/index.php?show=contact&id=3

应显示:

www.domain.com/contact

在该页面内我想得到($ _GET ['id'])id。

请帮助我,我被卡住了......

1 个答案:

答案 0 :(得分:0)

有一个单独的规则可以像这样处理/contact

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]

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

RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?show=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=302,L]

Header set X-UA-Compatible "IE=Edge,chrome=1"

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?show=$1&id=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ index.php?show=$1 [L,QSA]