gpt4 book ai didi

php - 删除子文件夹的代码点火器中的 index.php

转载 作者:行者123 更新时间:2023-12-05 04:10:39 25 4
gpt4 key购买 nike

我有一些问题。在开发中,我使用的是 php 7,我的网站运行良好。但在生产中它使用 php 5.4,我在删除 index.php 时遇到问题。我的网站托管在子文件夹中,就像 myhost/mywebsitefolder 一样。

问题是在使用 url 函数时。例如,当我访问“仪表板”页面时,它将重定向到“登录”页面,并且 url 类似于 myhost/mywebsitefolder/login 并返回 404 页面未找到。当我在登录前添加 index.php (myhost/mywebsitefolder/index.php/login) 时,它运行良好,但我必须通过添加 index.php 来替换我的所有 url。有什么解决办法吗。我的 .htaccess 就是这样。

RewriteEngine on
RewriteBase /mywebsitefolder/
RewriteCond $1 !^(index.php|resources|gallery|json|slider|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

最佳答案

尝试在点之前加上斜杠,例如:

DirectoryIndex index.php

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /mywebsitefolder
RewriteCond $1 !^(index\.php|resources|gallery|json|slider|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>

并在application/config/config.php 中清除索引页面配置值:

// Old
$config['index_page'] = "index.php";

// New
$config['index_page'] = "";

有时你需要启用重写模块,运行“apache2 enable module rewrite”:

sudo a2enmod rewrite

您需要重新启动网络服务器以应用更改:

sudo service apache2 restart

希望它有用!

如果没有,还有其他线程有同样的问题,你可以看看:- Remove index.php from codeigniter in subfolder- Remove index.php from Codeigniter URL in subfolder with Wordpress in root- Using htaccess to remove codeigniter index.php in a subdirectory

关于php - 删除子文件夹的代码点火器中的 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44098633/

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