【问题标题】:MVC URL RedirectMVC URL 重定向
【发布时间】:2015-02-26 21:15:01
【问题描述】:

我目前正在使用自定义 MVC 架构来创建我的网站。

问题是,当我输入 localhost/website/(将来会是 www.website.com/)时,我希望显示我的主页。目前我正在使用 localhost/website/home/ 来完成这项工作,但我不希望这样做,我只想要 localhost/website/ 自动显示主页。

我曾尝试使用 htaccess 执行此操作,但没有任何成功。当我导航到 localhost/website/ 时,它显示错误“此网页不可用”。

我的 htaccess 代码:可以在我的公共文件夹中找到。

     <IfModule mod_rewrite.c>
         RewriteEngine On

         RewriteCond %{REQUEST_FILENAME} !-f
             RewriteCond %{REQUEST_FILENAME} !-d

        RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

        </IfModule>
        <IfModule !mod_rewrite.c>
            ErrorDocument 404 index.php
        </IfModule>

我希望这是有道理的,并且有人可以帮助我。

谢谢

【问题讨论】:

    标签: php .htaccess url redirect


    【解决方案1】:

    你可以有一个这样的新规则:

    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        # handle home page
        RewriteRule ^/?$ home [L]
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
       ErrorDocument 404 index.php
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      尝试在该行之后添加:RewriteEngine On 此规则:

      RewriteRule ^$ index.php?url=home [L]
      

      【讨论】:

        猜你喜欢
        • 2014-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-19
        • 1970-01-01
        • 1970-01-01
        • 2016-02-03
        相关资源
        最近更新 更多