gpt4 book ai didi

linux - 具有相对路径重定向的 Mod_Rewrite

转载 作者:IT王子 更新时间:2023-10-29 01:10:36 26 4
gpt4 key购买 nike

我在名为 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,这仍然是错误的。如果这些文件在网站的目录树中移动,我不想指定绝对路径。我怎样才能使它相对而不是绝对起作用?

最佳答案

尝试如下添加 RewriteBase 指令

RewriteEngine On
RewriteBase /clips/

RewriteRule ^mlk/?$ segment/index.php?clip=1 [R=301,QSA,L]

编辑

but is there any way to get this to work without using a RewriteBase directive

你也可以试试

RewriteEngine On


RewriteCond %{REQUEST_URI} ^(/[^/]+/) [NC]
RewriteRule ^mlk/?$ http://%{HTTP_HOST}%1segment/index.php?clip=1 [R=301,QSA,L]

关于linux - 具有相对路径重定向的 Mod_Rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9102358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com