【问题标题】:Moving codeigniter project to a new hosting provider - .htaccess and index.php将 codeigniter 项目移至新的托管服务提供商 - .htaccess 和 index.php
【发布时间】:2012-11-08 17:40:45
【问题描述】:

我刚刚将我的功能性 codeigniter 项目转移到了一个新的网络托管服务提供商,现在我遇到了使用标准 .htaccess mod-rewrite 从 URL 中删除 index.php 的挑战。这是运行良好的 .htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

我找到了this 讨论,但我没有 apache 服务器的 root 访问权限来进行建议的配置更改。

使用上面提供的 .htaccess 文件,

欢迎提出任何建议。

【问题讨论】:

  • 由于您的问题显然不准确,请编辑它并真正解释您真正想要的内容:浏览器应该使用哪种 URL 格式?服务器端应用程序使用什么内部 URL 结构?不要指望我们猜测你想要什么......

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

如果你真的必须同时接受这两种形式的 URL,那么你需要两个 RewriteRules。一旦接受带有“index.php”部分的变体和一个没有的变体。

类似这样的:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index\.php/(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

【讨论】:

  • 感谢您的建议,但是我不需要/不想接受 URL 中的 index.php,所以我真的不需要第一个 RewriteRule。
  • 那我完全不明白你的问题,对不起。
【解决方案2】:

您的问题不是很清楚,但是像这样的 mod_rewrite 规则的一个常见问题是某些服务器需要将请求作为查询传递。 IE。您需要将最后一行更改为:

RewriteRule ^(.*)$ index.php?/$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多