【问题标题】:htaccess not working on my VPS with cpanelhtaccess 无法使用 cpanel 在我的 VPS 上工作
【发布时间】:2011-09-22 21:13:30
【问题描述】:

我有一个网站,它位于带有 directadmin 控制面板的 VPS 上,但我刚刚使用 Cpanel 移动到另一个 VPS。它曾经在旧 VPS 上运行时可以工作,但在新 VPS 上我无法使其工作..!!

我的脚本是 CodeIgniter 脚本,在这个脚本中这个 url:

www.mydomain.com/index.php/news

应转换为:

www.mydomain.com/news

但是使用htaccess后,我可以大大打开主页(即index.php)但是当我想去www.mydomain.com/news时(这个应该定义为www.mydomain.com/index.php) php/news by htacces )它显示了我的主页。我已经在 public_html 文件夹(位于 home/user 下)中安装了 CodeIgniter(我用于脚本的框架)。

我拥有对我的 VPS、WHM/Cpanel 的完全管理员访问权限,我可以进行任何更改。

这是在我的旧 VPS 中为我​​工作的 .htaccess:

Options FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on

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

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

我刚刚通过转换这一行发现:

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

到这个:

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

意味着将标志[L]更改为[R],它可以工作,但它只是将www.domain.com/news转换为www.domain.com/index.php/news 并显示在地址栏中,这不是我想要的。

你有什么解决办法吗?!我应该更改 Cpanel 上的任何配置吗?!

【问题讨论】:

  • 1) 也许您有一个名为news 的真实文件或文件夹? 2)做一个简单的调试:改变你的规则重写到echo.php文件,创建一个并把它里面:&lt;?php phpinfo(INFO_VARIABLES);那里寻找_SERVER["REQUEST_URI"]_SERVER["QUERY_STRING"]的值——它可能会给你一些提示。其他 -- 启用重写调试 (RewriteLog & RewriteLevel 9) 并查看日志内容。
  • 谢谢,_SERVER["REQUEST_URI"] is /news _SERVER["QUERY_STRING"] is no value 这些与旧 VPS 相同,似乎工作正常,唯一的区别是新 VPS 我也有 _ENV["REQUEST_URI"] 和 _ENV["QUERY_STRING"] 值。这些是什么?!
  • _ENV ... 我的设置中没有它们——你可能会以不同的方式运行 PHP(我将它作为 Apache 模块运行,而不是 CGI 或 FastCGI,它们可能在你的设置中) .无论如何 - 到目前为止它对我来说看起来不错。您还可以检查_SERVER["PHP_SELF"] 的值吗?如果重写工作正常,那么它应该是/echo.php/news(访问domain.com/news时)。

标签: .htaccess cpanel


【解决方案1】:

试试这个:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond $1 !^(index\.php|images|css|js|favicon\.ico|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

希望它适用于您的 CodeIgniter 安装,我遇到了同样的问题,这解决了它。

【讨论】:

    猜你喜欢
    • 2012-12-10
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-03-24
    • 2019-04-02
    • 2013-06-14
    • 1970-01-01
    • 2014-03-31
    相关资源
    最近更新 更多