Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么在添加htaccess规则后,特定页面中的XHR调用不起作用?_Php_.htaccess - Fatal编程技术网

Php 为什么在添加htaccess规则后,特定页面中的XHR调用不起作用?

Php 为什么在添加htaccess规则后,特定页面中的XHR调用不起作用?,php,.htaccess,Php,.htaccess,我是htaccess的新手,对正则表达式非常不好,所以这里什么都没有 我正在构建一个非常简单和基本的web应用程序。 我有5页,处理应用程序中的所有内容 home.php login.php content.php admin.php error.php 主页只处理主页;登录只处理登录和帐户创建;内容处理站点中的所有其他页面;admin只处理登录后面的admin部分;错误处理错误-清楚 为了实现这一点,我必须制定一些古怪的访问规则。登录表单是通过ajax提交的,因此这是第一个障碍 我已经成功

我是htaccess的新手,对正则表达式非常不好,所以这里什么都没有

我正在构建一个非常简单和基本的web应用程序。 我有5页,处理应用程序中的所有内容

  • home.php
  • login.php
  • content.php
  • admin.php
  • error.php
主页只处理主页;登录只处理登录和帐户创建;内容处理站点中的所有其他页面;admin只处理登录后面的admin部分;错误处理错误-清楚

为了实现这一点,我必须制定一些古怪的访问规则。登录表单是通过ajax提交的,因此这是第一个障碍

我已经成功地将登录重定向到管理门户,管理门户将显示出来,但是注销将不起作用,管理门户中的ajax功能也将不起作用

以下是我目前的访问权限:

#I have no idea what this line does
Options -Indexes

# Turn on rewritting
RewriteEngine On

# This will get the admin portal to load it needs to go through the admin controller 
# not content, but nothing inside admin works
# /admin - works! 
# /admin/save, /admin/logout, /admin/getPage all fail and are submitted via ajax
RewriteCond %{REQUEST_URI} ^/(.*)/admin$
RewriteRule ^(.*)$ index.php?url=admin/default/ [L,NC,QSA]

# this let's the login form submission via ajax work successfully, otherwise it gets 
# processed by the last rule as a content page - it needs to go through the login 
# controller, not content.
RewriteCond %{REQUEST_URI} ^/(.*)/login/login$
RewriteRule ^(.*)$ index.php?url=login/login/ [L,NC,QSA]

# this handles all the other pages in the site successfully
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=content/default/$1 [L,NC,QSA]

我整天都在互联网上搜索这个问题的答案,我的答案可能是完全错误的,如果是,请让我知道,并让我知道为什么以及如何解决它(我想最后两个是可选的)。一旦我开始工作,我的申请就准备好了。我们将衷心感谢您的帮助

使用查询字符串变量(如
url
)的一个更好的替代方法是:

  • 通过index.php解析每个请求
  • $\u服务器
    全局变量的
    REQUEST\u URI
    值读取URI路径,并从
    REQUEST\u method
    读取HTTP方法。将它们与其他全局变量($\u POST、$\u GET等)的值一起保存到
    请求
    对象中(例如,名为
    请求
    的类的实例)
  • 买一个路由器(我个人的选择)并建立你的路由列表-请阅读文档。每个路由都被定义为一个对象,具有HTTP方法、模式和处理程序(例如控制器方法,例如操作)作为属性
  • 将请求组件(HTTP方法和来自
    请求
    对象的URI路径)与路由列表中每个路由对象的组件(HTTP方法和模式属性)进行比较
  • 如果找到匹配项,例如如果请求组件与路由组件相同,则调用相应的路由处理程序,例如控制器操作。将
    Request
    对象作为参数传递,以便能够读取POST、GET等值
现在关于配置(对于Apache 2.2):

首先,不要忘记拒绝访问所有文件夹

<Directory />
    Options None
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
httpd vhosts demoproj.conf

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "/path-to/htdocs"
</VirtualHost>

<VirtualHost *:80>
    ServerName local.demoproj
    DocumentRoot "/path-to/demoproj/public"
    Include "/path-to/httpd-vhosts-demoproj.conf"
</VirtualHost>
<Directory "/path-to/demoproj/public">
    Allow from all

    # When off then RewriteRule directive is forbidden!
    # ---------------------------------------------------------------------------------------------
    # https://stackoverflow.com/questions/12120035/what-is-options-followsymlinks/26732503#26732503
    # https://stackoverflow.com/questions/12120035/what-is-options-followsymlinks/12129326#12129326
    # ---------------------------------------------------------------------------------------------
    Options FollowSymLinks

    # Activate rewriting engine.
    RewriteEngine On

    # Allow pin-pointing to index.php using RewriteRule.
    RewriteBase /

    # Rewrite url only if no physical folder name is given in url.
    RewriteCond %{REQUEST_FILENAME} !-d

    # Rewrite url only if no physical file name is given in url.
    RewriteCond %{REQUEST_FILENAME} !-f

    # Parse the request through index.php.
    # -----------------------------------------------------------------------------------------------------
    # https://httpd.apache.org/docs/current/rewrite/flags.html "RewriteRule Flags"
    # https://stackoverflow.com/questions/45997912/exposed-folders-in-mvc-application/45998123#45998123
    # https://stackoverflow.com/questions/2102128/mod-rewrite-what-does-this-rewriterule-do/2102189#2102189
    # -----------------------------------------------------------------------------------------------------
    RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>

通融
#禁用时,则禁止重写规则指令!
# ---------------------------------------------------------------------------------------------
# https://stackoverflow.com/questions/12120035/what-is-options-followsymlinks/26732503#26732503
# https://stackoverflow.com/questions/12120035/what-is-options-followsymlinks/12129326#12129326
# ---------------------------------------------------------------------------------------------
选项如下符号链接
#启动重写引擎。
重新启动发动机
#允许使用RewriteRule将pin指向index.php。
重写基/
#仅当url中未给出物理文件夹名称时,才重写url。
重写cond%{REQUEST_FILENAME}-D
#仅当url中未给出物理文件名时重写url。
重写cond%{REQUEST_FILENAME}-F
#通过index.php解析请求。
# -----------------------------------------------------------------------------------------------------
# https://httpd.apache.org/docs/current/rewrite/flags.html “重写规则标志”
# https://stackoverflow.com/questions/45997912/exposed-folders-in-mvc-application/45998123#45998123
# https://stackoverflow.com/questions/2102128/mod-rewrite-what-does-this-rewriterule-do/2102189#2102189
# -----------------------------------------------------------------------------------------------------
重写规则^(.*)$index.php[QSA,L]