htaccess mod 重写 url 显示 404


htaccess mod rewriting url displays 404

#Create friendly URL
RewriteRule ^$1-$2.php?$3=$4$ (.*)/(.*)/(.*)/(.*)/[L]

你好,再次堆叠溢出!

我的网站的当前站点(我们称之为 site.com(具有以下设置:


http://site.com/category/page/variable1/value1/variable2/value2/
http://site.com/category/page/variable1/value1/
http://site.com/category/page/http://site.com/

我想将这些网址重写为:


http://site.com/category-page.php?variable1=value1&variable2=value2
http://site.com/category-page.php?variable1=value1
http://site.com/category-page.phphttp://site.com/

上面的代码是我尝试编写的代码。它没有给我服务器错误消息,而是显然不起作用 - 当我去 http://site.com/category/page/variable1/value1/variable2/value2/时,它只会给出 404 错误。

你们能帮我吗?

提前致谢

我认为你的正则表达式和替换是倒退的。下面的代码片段只是计算/捕获斜杠之间的内容以进行重写。

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/ /$1-$2.php?$3=$4&$5=$6 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) /$1-$2.php?$3=$4 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ $1-$2.php [L]