我有一个模式重写的网站。问题是,当在重写的网址中有一个点,它会导致404.我试过this帖子
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*).(.*)$ /$1$2 [L,R=301]
RewriteRule ^page/cart/([^./]+)/?$ ./index.php?page=cart&$1 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&id=$4&name=$5 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&name=$4 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&name=$3 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&id=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1&name=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1 [L,PT]
但它仍然给了我404。我的目标是当我在网址中点,永久重定向到没有点的相同网址。
我怎么能实现这个目标?
修改
我使用此组合编辑了我的文件以排除所有图像,但似乎第一个条件不适用:
RewriteCond %{REQUEST_URI} !=/(.*)\.(jpg|gif|png|css|js)$ [NC]
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*)\.(.*)$ /$1$2 [L,R=301]
RewriteRule ^page/cart/([^./]+)/?$ ./index.php?page=cart&$1 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&id=$4&name=$5 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&name=$4 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&name=$3 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&id=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1&name=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1 [L,PT]
编辑2:
我发现了自己的错误。
第一行应为RewriteCond %{REQUEST_URI} !\.(jpg|gif|png|css|js)$ [NC]
,而不是RewriteCond %{REQUEST_URI} !=(.*)\.(jpg|gif|png|css|js)$ [NC]
感谢。
答案 0 :(得分:2)
您需要转义.
:
RewriteRule ^(.*)\.(.*)$ /$1$2 [L,R=301]
正则表达式中保留.
字符表示“任何不是换行符的字符”。