-3

有没有办法用斜杠替换所有问号、'&'和等号???

目前我只用 .html 替换 php 扩展

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [nc] 

现在,如果网站网址是这个

http://www.mydomain.com/session/image-display.php?image=1&id=59

用户应该得到

http://www.mydomain.com/session/image-display.html/image/1/id/59

--已编辑--

我只需要一个示例,以便我也可以为其他页面编写它们。还如何重写 2 个或更多重写规则?

4

4 回答 4

0

根据您提供的示例,您可以使用它:

RewriteRule ^session/image-display.html/image/(.*)/id/(.*) 
/session/image-display.php?image=$1&id=$2 [L]

最后的 [L] 是可选的,它告诉 Apache 如果应用了这条规则,则停止寻找其他规则

于 2013-10-25T05:57:56.357 回答
0

您需要更改链接,使它们看起来像:

http://www.mydomain.com/session/image-display.html/image/1/id/59

然后将其添加到文档根目录中的 htaccess 文件中,在您可能已经拥有的任何规则之前:

RewriteCond %{THE_REQUEST} \ /session/image-display\.php\?image=([^&]+)&id=([^&\ ]+)
RewriteRule ^ /session/image-display.html/image/%1/id/%2? [L,R=301]

RewriteRule ^session/image-display\.html/image/([^/]+)/id/([^/]+) /session/image-display.php?image=$1&id=$2 [L]
于 2013-10-25T05:58:42.317 回答
0

在 .htaccess 中试试这个:

RewriteRule ^(.*)\.html/image/([^/]+)/id/([^/]+)$ $1.php?image=$2&id=$3 [NC]
于 2013-10-25T05:58:55.683 回答
0

这两条规则将在内部重写/session/image-display.html/n1/v1/n2/v2/n3/v3/session/image-display.php?n3=v3&n2=v2&n1=v1

可以有任意数量的/name/value ,因为此规则非常通用。

# this rule will be applied as many times as there are /name/value pairs in URI
# after /session/image-display.html
RewriteRule ^(session/image-display\.html)/([^/]*)/([^/]*)(.*)$ /$1/$4?$2=$3 [L,QSA,NC]

# this rule be applied in the last then all /name/value pairs have been converted
# into query string
RewriteRule ^(session/image-display)\.html/?$ /$1.php [L,NC]
于 2013-10-25T06:59:24.760 回答