CodeIgniter本地主机重定向到xampp主屏幕

6
当我在浏览器中使用localhost/hr运行CI项目时,它会将我重定向到localhost/dashboard/。搜索了不同的解决方案但都没有使其工作。这是我在"htdocs/hr"文件夹中的.htaccess文件。
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

注意:在 htdocs 文件夹中没有 .htaccess 文件。
当我删除/重命名 index.php 文件并访问 htdocs 时,它会给出错误。
Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again. 

我做错了什么,如何让它正常工作?

我的htdocs/hr文件夹的截图如下所示:

enter image description here


你的route.php文件中有什么内容? - Snm
$route['default_controller'] = "site"; $route['404_override'] = ''; - Noman Ali
2
RewriteEngine On 之后放置 RewriteBase /hr/ - Kamran
2个回答

8

您需要在位于您文件夹中的.htaccess文件中设置RewriteBase,这在您的情况下是ci。

所以您目前有:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

您应该将其更改为
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ci/

就是这样。现在它会正常工作。


非常感谢你的帮助 :) - Noman Ali
很高兴能帮到你 :) - Shahbaz A.
@NomanAli 如果这个答案解决了你的问题,你应该接受它,这将有助于未来的访问者。 - Shahbaz A.

2
请查看RewriteBase指令,然后尝试以下操作:
RewriteEngine on
RewriteBase /hr/

RewriteCond %{REQUEST_URI} !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

此外,您需要确保启用了Apache的重写模块:
# Check if it's enabled:
apachectl -M | grep rewrite

# You might need sudo here:
a2enmod rewrite

# On platforms that a2enmod is not available, you need 
# to open up your httpd.conf file and uncomment the line
# that looks like this:
LoadModule rewrite_module libexec/mod_rewrite.so

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接