将所有流量重定向到 root 以将文件包含在路径 mod_rewrite 中

发布于 2024-10-22 01:39:14 字数 583 浏览 1 评论 0原文

我试图找出如何将所有请求重定向到:

http://www.i2systems.com

在 url 中包含“index.php”,如下所示:

http://www.i2systems.com/index.php

此请求:

http://www.i2systems.com/services/supply-chain-design/

变为:

http://www.i2systems.com/index.php/services/supply-chain-design/

我怎样才能实现此目的 - 我已经尝试过这个,但它不起作用:

RewriteCond %{HTTP_HOST} ^i2systems.com [NC]<br>
RewriteRule ^(.*)$ http://www.i2systems.com/$1 [L,R=301]<br>
RewriteRule ^$ index.php [L]

I'm trying to figure out how to redirect all requests to:

http://www.i2systems.com

To include "index.php" in url like this:

http://www.i2systems.com/index.php

This request:

http://www.i2systems.com/services/supply-chain-design/

becomes this:

http://www.i2systems.com/index.php/services/supply-chain-design/

How can I achieve this - I have tried this, but its not working:

RewriteCond %{HTTP_HOST} ^i2systems.com [NC]<br>
RewriteRule ^(.*)$ http://www.i2systems.com/$1 [L,R=301]<br>
RewriteRule ^$ index.php [L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洛阳烟雨空心柳 2024-10-29 01:39:14

我建议这样:

RewriteEngine On    
RewriteCond %{REQUEST_URI} !^/index.php/.*
RewriteRule (.+) /index.php/$1 [R=301,L]

因为当index.php已经存在于请求URI的开头时,不要重定向是很重要的。

更新:为了避免 css、js 重定向,请尝试以下操作(假设您只想按照原始问题重定向 /services/ 路径):

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/services/.*
RewriteRule (.*) /index.php/$1 [R=301,L]

I would suggest something like this:

RewriteEngine On    
RewriteCond %{REQUEST_URI} !^/index.php/.*
RewriteRule (.+) /index.php/$1 [R=301,L]

Since it is important to NOT to redirect when index.php is already present at the start of request URI.

Update: To avoid css, js redirection try this (assuming you only want /services/ path to redirect as per your original question):

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/services/.*
RewriteRule (.*) /index.php/$1 [R=301,L]
话少情深 2024-10-29 01:39:14
RewriteEngine On

RewriteCond %{query_string} ^(.*)
RewriteRule (.*) index.php/$1?%1
RewriteEngine On

RewriteCond %{query_string} ^(.*)
RewriteRule (.*) index.php/$1?%1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文