【问题标题】:.htaccess url routing subdirectory.htaccess url 路由子目录
【发布时间】:2012-10-02 21:48:39
【问题描述】:

我已经阅读了至少 100 篇关于 .htaccess 的帖子,但似乎无法理解它。我尝试的一切都导致了 404 错误,我知道它有效,因为如果我输入一行随机数,它会给出不同的错误。我正在尝试做的是 url 路由,就像使用索引页面一样,使用子域。

我有一个文件 routing.php,它采用 URL 后面的部分,并包含基于创建不同页面的文件。

EX:mydomain.com/secure/routing/application 应该通过路由路由给它变量应用程序,以便routing.php 可以构建应用程序。 mydomain.com/secure/routing/login 应该通过路由给它变量 login 从而构建一个登录页面。

我已经设置好了routing.php。细分,将任何包含mydomain.com/secure/routing/ 的url 路由到mydomain.com/secure/routing.php,无论路由之后发生什么。

我最近的尝试:(放在 /secure 子目录中)

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
#  Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . routing.php

【问题讨论】:

    标签: apache .htaccess webserver


    【解决方案1】:

    试试:

    Options +FollowSymLinks
    IndexIgnore */*
    # Turn on the RewriteEngine
    RewriteEngine On
    
    RewriteBase /secure/
    
    #  Rules
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^routing/? routing.php [L]
    

    【讨论】:

    • 那是我在长期探索中尝试过的一种。我刚刚又试了一次,仍然收到 404 错误。
    • @user860869 从我的文档根目录创建secure 子目录,创建routing.php 文件并将上述内容放入空白htaccess 文件时工作正常。 routing.php 输出显示:[REQUEST_URI] => /secure/routing/qweqweqwe/123213213/sdsfds,所以我可以看到我的请求正在路由到 routing.php。您确定返回 404 的不是 routing.php 吗?
    • 自己看,aliahealthcare.com/secure/routing.php 是我的页面,删除最后的 .php 仍然应该加载相同的页面,但它只加载 404
    • @user860869 这些规则在您的/secure/ 目录中的一个htaccess 文件中,您的服务器配置中有AllowOverride All 并且实际上正在应用htaccess 文件中的规则?
    • 我遇到了这个问题,我如何验证它们正在被应用。就像我说的,如果我在 .htaccess 文件中键入一堆 1 并重新加载页面,我会收到内部服务器错误。同样是的,这些规则是空的 .htaccess 的一部分,因此 url 看起来像 mydomain.com/secure/.htaccess
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    相关资源
    最近更新 更多