带相对路径重定向的 Mod_Rewrite
我在名为 clips/
的目录中的 .htaccess 文件中有此规则:
RewriteRule ^mlk/?$ segment/index.php?clip=1 [R=301,QSA,L]
我的目的是,当有人访问 http://example.local/clips/mlk
时> 它们被重定向到 http://example.local/clips/segment/index.php?clip=1
实际发生的情况是,当有人访问 example 时.local/clips/mlk
它们被重定向到 example.local/var/www/example/clips/segment/index.php?clip=1
我不确定为什么要这样做。如果我将重写规则更改为:
RewriteRule ^mlk/?$ /segment/index.php?clip=1 [R=301,QSA,L]
用户被重定向到 example.local/segment/index.php?clip=1,这仍然不正确。当这些文件在网站的目录树中移动时,我不想指定绝对路径。我怎样才能让它相对而不是绝对地工作?
I have this rule in an .htaccess file located in a directory named clips/
:
RewriteRule ^mlk/?$ segment/index.php?clip=1 [R=301,QSA,L]
What I am intending is that when someone visits http://example.local/clips/mlk
they are redirected to http://example.local/clips/segment/index.php?clip=1
What actually happens is that when someone visits example.local/clips/mlk
they are redirected to example.local/var/www/example/clips/segment/index.php?clip=1
I'm not sure why it's doing this. If I change the rewrite rule to this:
RewriteRule ^mlk/?$ /segment/index.php?clip=1 [R=301,QSA,L]
The user is redirected to example.local/segment/index.php?clip=1, which is still incorrect. I don't want to have to specify an absolute path in the case of these files being moved around the website's directory tree. How can I get this to work relatively instead of absolutely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加如下 RewriteBase 指令
编辑
你也可以尝试
Try adding a RewriteBase directive as below
EDIT
You could also try