2012-03-20 87 views
0

我环顾四周寻找答案,没有运气。需要.htaccess重写规则建议

我想要做的就是更换

http://localhost/mysite/superv/something

http://localhost/mysite/superv/?p=something

这是我从昨天起想出了最佳配方:

RewriteEngine On 
RewriteBase /mysite/ 
RewriteRule ^(superv/)([^\?/]+)$ $1\?p=$2 [NC] 

但它不工作。

我觉得“RewriteBase”啄无关的问题,因为这条线的工作就像一个魅力:

RewriteRule ^(javascripts/main\.js)$ $1\.php [NC]

编辑:右键Rekire,这是一个错误,而复制和粘贴代码。我现在解决了这个问题。

EDIT2:下面是出现在Apache日志错误:

[Tue Mar 20 20:26:01 2012] [error] [client 127.0.0.1] 
Request exceeded the limit of 10 internal redirects due to probable configuration error. 
Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. 

我猜问题是 “循环”,我引述:

Looping occurs when the target of a rewrite rule matches the pattern. 
This results in an infinite loop of rewrites 
+0

那么,如果你写入你的'RewriteRule'“superv”,但你试图用“admin”来管理一个URL,那么这是行不通的。 – rekire 2012-03-20 17:31:47

+0

请注意,评论者不会被通知编辑。我想知道你正试图将用户重定向到一个php文件的路径。这可能是你的问题。 – rekire 2012-03-20 18:14:01

+0

请勿在替换字符串中转义字符,例如'$ 1吗?P = $ 2'。另外你为什么[内部]重定向'http:// localhost/mysite/javascripts/main.js'到'http:// localhost/mysite/javascripts/main.js.php'? – TerryE 2012-03-20 20:36:57

回答

1

出于某种原因,这个公式的工作(内部重定向):

RewriteRule (.*)(superv/)?(.*) $1$2index.php?p=$3 [NC,QSA] 

这似乎已经打破了“无限循环”。

1

这似乎是为我工作。

RewriteRule ^(superv/)([^\?/]+)$ $1?p=$2 [R,NC] 

删除R,如果你想做一个内部重定向。

+0

嗨,您的线路工作,但一旦我删除R我得到相同的“500内部服务器错误”和“请求超出限制”错误。 – 2012-03-21 15:47:30