【问题标题】:How to change index.php file path loading in .htaccess如何更改 .htaccess 中的 index.php 文件路径加载
【发布时间】:2014-02-21 22:24:17
【问题描述】:

我需要更改我的index.php文件加载路径所以我放置如下,

httpdocs
    new_path
         index.php

我更新了我的 .htaccess 如下,

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ new_path/index.php [NC,L]

但是当我访问http://www.mysite.com 时,它说浏览器找不到该页面。谁能帮我解决这个问题?

谢谢

【问题讨论】:

    标签: php .htaccess redirect rewrite


    【解决方案1】:

    我在上面的问题中提到的所有代码下方都放置了粗体代码。

    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^.*$ new_path/index.php [NC,L]
    

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d 
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ new_path/index.php [NC,L]
    

    【讨论】:

      【解决方案2】:

      在你的根 .htaccess 中试试这个:

      RewriteEngine On
      
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule .* new_path/index.php [L]
      

      【讨论】:

      • 我之前试过你的例子我得到了同样的结果。我什至尝试过您的回复,但没有成功。
      • 验证您的.htaccess 是否启用,方法是在您的.htaccess 顶部放置相同的垃圾(随机)文本,看看它是否会产生500(内部服务器)错误?跨度>
      • 是的,我得到 500(内部服务器)
      • 所以http://www.mysite.com/ 得到 404?你打开http://www.mysite.com/new_path/index.php会发生什么?
      • 如果我加载 mysite.com 浏览器说找不到页面但如果我打开 mysite.com/new_path/index.php url 那么它就可以工作了。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 2012-06-19
      • 2012-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多