首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从中间删除index.php

如何从中间删除index.php
EN

Stack Overflow用户
提问于 2022-02-16 07:51:31
回答 1查看 76关注 0票数 1
  1. 我想从URL中间删除index.php。
  2. 我使用的是Dreamhost not主机,相信我,梦想主机的网络托管配置与其他的非常不同。
  3. 正常的not托管配置在Dreamhost中不起作用。

这里是我面临的问题:

问题1:

代码语言:javascript
复制
The link below:
https://www.example.com/index.php/gallery

Should redirect to:
https://www.example.com/gallery

问题2:

代码语言:javascript
复制
The link below:
https://www.example.com/index.php/profile/juhi/168

Should redirect to:
https://www.example.com/profile/juhi/168

问题3:

代码语言:javascript
复制
The link below:
https://www.example.com/index.php

Should redirect to:
https://www.example.com/

htaccess代码如下:

代码语言:javascript
复制
RewriteEngine On

# Existing files and directories remain accessible
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]

# Redirect the rest
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
EN

回答 1

Stack Overflow用户

发布于 2022-02-16 13:30:54

https://www.example.com/index.php/gallery

/index.php (有效文件)之后的URL-path部分,即.在本例中,/gallery被称为“附加路径名信息”(又名路径信息)。(当mod_rewrite/.htaccess不可用时,许多CMS使用它来路由URL。)

要删除URL的/index.php部分,可以在RewriteEngine指令之后添加以下重定向指令。

代码语言:javascript
复制
# Redirect URLs of the form "/index.php/<URL>" to "/<URL>"
# Also handles "/index.php" only
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index.php(?:/(.*))?$ /$1 [R=301,L]

首先使用302 (临时)重定向测试,并且只更改为301 (永久的)--如果这是意图的话--一旦您确认它按预期工作。301系统由浏览器持久地缓存,因此可能会造成测试问题。

撇开:

RewriteRule ^(.*)$ /index.php?/$1 QSA,L

正如我在注释中提到的,您的.htaccess指令正在将请求重写为查询字符串(而不是上面提到的path-info )。这意味着您的页面可以通过第三个URL访问。例如:

代码语言:javascript
复制
/index.php?/gallery
/index.php?/profile/juhi/168

我使用的是梦想主机( Dreamhost Webhosting.

  • And ),相信我,梦想主机的网络托管配置与others.

  • Normal的not主机配置有很大不同。

FWIW,在您的问题或解决方案中没有提到,是特定于任何特定的网络主机。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71138032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档