加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 00:51:55 所属栏目:Linux 来源:网络整理
导读:我在位于名为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
我在位于名为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,L]

用户被重定向到example.local / segment / index.php?clip = 1,这仍然是不正确的.我不想在这些文件在网站目录树中移动的情况下指定绝对路径.我怎样才能让它相对而不是绝对地工作?

解决方法

尝试添加RewriteBase指令,如下所示

RewriteEngine On
RewriteBase /clips/

RewriteRule ^mlk/?$segment/index.php?clip=1 [R=301,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,L]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读