简体   繁体   English

mod_rewrite()内部重定向过多

[英]mod_rewrite() too many internal redirects

I have successfully implemented the basic facebook like URLs: 我已经成功实现了URL之类的基本Facebook:

http://example.com/(username) which internally calls http://example.com/sites/(username) using the following mod_rewrite code: http://example.com/(用户名) ,它使用以下mod_rewrite代码内部调用http://example.com/sites/(用户名)

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L]

Please note that the (username) folder exists inside the sites folder 请注意,(用户名)文件夹位于站点文件夹内

The above works perfectly fine. 以上工作完全正常。 But now i want to prettify my other urls like: http://example.com/(username)/Image/2/ this should internally call http://example.com/sites/(username)/index.php?type=image&id=2 但是现在我想美化我的其他网址,例如: http : //example.com/(用户名)/ Image / 2 /这应该在内部调用http://example.com/sites/(用户名)/index.php?type = image&id = 2

To do this i added the following code in the second last line: 为此,我在倒数第二行中添加了以下代码:

RewriteRule ^([^/]+)/Image/(.*)$ /sites/$1/index.php?type=image&id=$2 [NC,L]

I was hoping the [L] at the end will stop the rule from being computed after this. 我希望最后的[L]将阻止此后的规则计算。 But from the logs it turns out it goes into an infinite loop and is truncated. 但是从日志中发现它进入了无限循环并被截断。

Can someone point out what i'm doing wrong here? 有人可以指出我在做什么错吗?

Inside your DocumentRoot folder you can have this .htaccess: 在您的DocumentRoot文件夹中,您可以拥有以下.htaccess文件:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/(\d+)/?$ sites/$1/index.php?type=$2*id=$3 [QSA,L]

RewriteRule ^((?!sites[^/]+)(/.*)?$ sites/$1$2 [NC,L]

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

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