2013-08-02 57 views
0
#Create friendly URL 
RewriteRule ^$1-$2.php?$3=$4$ (.*)/(.*)/(.*)/(.*)/[L] 

你好又一次stackoverflow!htaccess mod重写url显示404

我的网站目前siteup(姑且称之为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/

我想重写这些URL对:

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

上面的代码是一个我试图写。它不会给我服务器错误消息,但反而只是显然不工作 - 当我去http://site.com/category/page/variable1/value1/variable2/value2/,它只是给出了一个404错误。

你们能帮我吗?

在此先感谢

+0

正则表达式和替换在您的RewriteRule中切换。你也提供了六个路径段的例子,但你的规则只允许四个。你有没有检查http://stackoverflow.com/tags/mod-rewrite/info标签wiki中的例子呢? – mario

+0

http://stackoverflow.com/questions/1882694/mod-rewrite-pass-the-path-query-string-url-as-a-parameter – hungerstar

+0

@mario这是我的设置的第二个例子,因为我只是测试了最初的重写。 – Thew

回答

1

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

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

我甚至无法访问根目录中的index.php文件。我该如何解决这个问题? – Thew

+0

解决了它,不得不与另一个htaccess文件。非常感谢你! – Thew