繁体   English   中英

.htaccess中的RewriteRule循环不起作用

[英]RewriteRule loop in .htaccess not working

我正在尝试为网站中的所有页面建立漂亮的链接,我想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。

# 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]行3次而没有标志无效。 除了第一个深度,它没有任何作用。 可能只是我的业余正则表达式,但我不明白发生了什么变化,有什么想法吗?

尝试这个 :

RewriteRule ^([\w-]+)/([\w-]+)$ $1-$2 [N]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=$1

看来您只需要调整正则表达式并重写标志:

# 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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM