【问题标题】:CodeIgniter Localhost redirecting to xampp homescreenCodeIgniter 本地主机重定向到 xampp 主屏幕
【发布时间】:2017-05-16 13:54:02
【问题描述】:

当我在浏览器中运行 CI 项目时,使用 localhost/hr,它会将我重定向到 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 文件夹的屏幕截图如下所示

【问题讨论】:

  • 你的 route.php 中有什么
  • $route['default_controller'] = "site"; $route['404_override'] = '';
  • RewriteEngine On之后放RewriteBase /hr/

标签: php apache .htaccess codeigniter url-rewriting


【解决方案1】:

您需要在您的文件夹中的.htaccess 文件中设置RewriteBase,在您的情况下为ci

所以你现在应该有

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

你应该把它改成

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ci/

就是这样。它现在可以工作了。

【讨论】:

  • 真的很欣赏男人:)
  • 很高兴它有帮助:)
  • @NomanAli 如果它解决了你的问题,你应该接受这个答案,这将有助于未来的访问者。
【解决方案2】:

看看RewriteBase directive,然后试试这个:

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

【讨论】:

    猜你喜欢
    • 2020-06-24
    • 2011-09-16
    • 2017-06-28
    • 2012-05-03
    • 2019-07-24
    • 2011-01-06
    • 2012-03-29
    • 2018-06-03
    • 1970-01-01
    相关资源
    最近更新 更多