有没有办法更换所有问号,'&' ,并用斜线等号???
目前我只用.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个或更多重写规则?
答案 0 :(得分:0)
根据您提供的示例,您可以使用:
RewriteRule ^session/image-display.html/image/(.*)/id/(.*)
/session/image-display.php?image=$1&id=$2 [L]
最后的[L]是可选的,它告诉Apache停止寻找其他规则(如果应用了这个规则)
答案 1 :(得分: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]
答案 2 :(得分:0)
在.htaccess:
中试试RewriteRule ^(.*)\.html/image/([^/]+)/id/([^/]+)$ $1.php?image=$2&id=$3 [NC]
答案 3 :(得分: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]