htaccess删除index.php?从网址

编程入门 行业动态 更新时间:2024-10-22 08:26:26
本文介绍了htaccess删除index.php?从网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要删除index.php吗?

I need to remove index.php? from URL.

来自: example/index.php?/discover/

收件人: forum.fibaro/discover/

我尝试了一切,但没有用:/

I tried everything, but doesn't work :/

推荐答案

我认为您正在尝试针对URI只有这样,让我在这里解释一下:

I think you were trying to mach against URI only so, let me explain something here :

example/index.php?/discover/

这部分 index.php 是URI,然后有是?,然后是 / discover / ,最后一部分是查询字符串,因此可以与之匹配 QUERY_STRING或THE_REQUEST 服务器变量根据您的需要,但是在使用 REQUEST_URI 时,您只能匹配URI部分。

This part index.php is URI , then there is ? and after that is /discover/ , the last part is query string so to match against it you could use QUERY_STRING or THE_REQUEST Server-Variables according to what you need but when using REQUEST_URI you match only against URI part.

尝试以下操作:

RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/index\.php\?\/(.*)\sHTTP.*$ RewriteRule ^index\.php$ /%1? [L,R=301] RewriteRule !^index\.php$ /index.php?%{REQUEST_URI} [L]

上面的代码会将 example/index.php?/discover/ 重定向到 example/discover/ 从外部,然后再次将其重定向到同一路径。

The code above will redirect example/index.php?/discover/ to example/discover/ externally and then redirect it again to same path .

注意:清除浏览器缓存,然后对其进行测试。

Note: clear browser cache then test it .

更多推荐

htaccess删除index.php?从网址

本文发布于:2023-10-31 18:53:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   htaccess   index   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!