循环重写规则在.htaccess不工作 [英] RewriteRule loop in .htaccess not working

查看:127
本文介绍了循环重写规则在.htaccess不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让pretty的链接在网站的所有页面, 我想 foo.com/services/domestic foo.com/index.php?page=services-domestic 。我有以下的在我的.htaccess文件和它的正常工作对于上面的例子,但如果我尝试去 foo.com/services/domestic/case/1 (期待 /index.php?page=services-domestic-case-1 ),我收到了404。

I'm trying to make pretty links for all the pages in a site, I'd like foo.com/services/domestic to go to foo.com/index.php?page=services-domestic. I have the following in my .htaccess file and it's working fine for the above example, but if I try to go to foo.com/services/domestic/case/1 (expecting /index.php?page=services-domestic-case-1) I get a 404.

# a/b/c/d -> a-b-c-d
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9_-]+)$ $1-$2 [N]

# a-b-c-d -> index.php?page=a-b-c-d
RewriteRule ^([^(/|\.)]+)$ index.php?page=$1

我已经试过只是重复 [N] 行三次无标志,无果。它不工作,但任何的第一深度。也许只是我的业余正则表达式,但我不明白发生了什么突破,任何想法?

I've tried just repeating the [N] line three times without the flag to no avail. It's not working for any but the first depth. Probably just my amateur regex but I can't understand what's breaking, any ideas?

推荐答案

看起来你只需要调整你的正常EX pressions并改写标志:

It looks like you just need to tweak your regular expressions and rewrite flags:

# a/b/c/d -> a-b-c-d
RewriteRule ^(.*)/(.*) /$1-$2 [L]

# a-b-c-d -> index.php?page=a-b-c-d
RewriteRule ^([^/.]+)$ /index.php?page=$1 [L]

这篇关于循环重写规则在.htaccess不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆