Web服务器不允许我刷新

Web服务器不允许我刷新

本文介绍了Apache Web服务器不允许我刷新/左右,但在本地主机上其工作罚款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我捆绑我的项目之一,它工作正常。但是路线上打刷新时/约,它显示所请求的网址/关于没有被这台服务器。但是,当我做这在我的本地掀起了网络服务器,它工作在刷新罚款和前进/后退按钮上找到。我使用的反应路由器为我的客户端的路由。

继承人的客户端路由,但我怀疑它的问题

  Router.run(路线,Router.HistoryLocation,功能(处理器){
    React.render(小于处理程序/>中的应用);
 });

和我的路就在那里:

 让路线=(
<路线和GT;
  <路线名称=应用程序PATH =/的处理程序= {}应用GT&;
    <路线名称=关于路径=/关于处理程序= {}简介/>
    <默认路由名称=项目的处理程序= {}项目/>
  < /路由>
< /路由>
        );

继承人的APACHE,我认为我打破了:

 <目录/ var / WWW />
                #这个指令可以让我们拥有的Apache2的默认启动页面
                #在/ Apache2的默认/,但仍然有/去正确的地方
要求所有批准
                #RedirectMatch ^ / $ / Apache2的默认/
        < /目录>

kkotwal.me.conf:

 <虚拟主机*:80>
        #ServerName指令设置请求方案,主机名和端口
        #服务器用来标识自己。这是在创建时使用
        #重定向URL。在虚拟主机的情况下,服务器名
        #指定了主机名必须出现在请求的Host:头
        #匹配这个虚拟主机。对于默认的虚拟主机(本文件)此
        因为它是无论使用作为最后的手段主机#值不是决定性的。
        #但是,你必须将其设置为任何其他虚拟主机明确。
        #
        服务器名kkotwal.me
        ServerAlias​​ www.kkotwal.me
        站长的ServerAdmin @本地
        DocumentRoot的/var/www/kkotwal.me/public_html        #可用记录等级:trace8,...,TRACE1,调试,信息,通知,警告,
        #错误,暴击,机警,EMERG。
        #它也可以配置为特定的日志级别
        #模块,例如
        #LogLevel信息SSL:警告        错误日志$ {} APACHE_LOG_DIR /error.log
        的CustomLog $ {} APACHE_LOG_DIR结合/access.log
< /虚拟主机>


解决方案

嘿,这实际上是一个pretty常见的事情。

发生了什么事是你需要让你的Apache服务器忽略任何嵌套的路径,只是将所有的请求 / * 根来代替。这样,你的前端JavaScript可以拿起客户端的路由,并显示正确的观点。

此有时在不同的Web服务器中称为HTML5模式

在阿帕奇这样做的方式是添加一条规则如下所示:

  RewriteEngine叙述在
  的RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  的RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI} -d
  重写规则^ - [L]  重写规则^ /index.html [L]

这是用来做什么告诉Apache服务存在的任何文件,但如果他们不存在,只是服务于 /index.html ,而不是一个404没有找到。

I bundled up one of my projects and it works fine. However when hitting refresh on a route /about, it displays The requested URL /about was not found on this server.. However when I do it on my localhost off a web server it works fine on refresh and forward/back buttons. I'm using react-router for my client side routing.

Heres the client side routing but I doubt its the problem

 Router.run(routes, Router.HistoryLocation, function (Handler) {
    React.render(<Handler/>, app);
 });

And my routes are just there:

let routes = (
<Route>
  <Route name = "App" path="/" handler = {App}>
    <Route name="About" path="/about" handler = {About}/>
    <DefaultRoute name="Projects" handler = {Projects}/>
  </Route>
</Route>
        );

Heres the APACHE that I think i broke:

<Directory /var/www/>
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
Require all granted
                #RedirectMatch ^/$ /apache2-default/
        </Directory>

kkotwal.me.conf:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #
        ServerName kkotwal.me
        ServerAlias www.kkotwal.me
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/kkotwal.me/public_html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
解决方案

Hey this is actually a pretty common thing.

What's happening is you need to get your apache server to ignore any nested paths and just send all requests /* to root instead. That way your front-end javascript can pick up the route on the client-side and display the correct view.

This is sometimes referred to as "HTML5 Mode" in different webservers.

In apache the way you do this is add a rule like the following:

  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]

  RewriteRule ^ /index.html [L]

What this does is to tell Apache to serve any files that exist, but if they dont exist, just serve /index.html rather than a 404 not found.

这篇关于Apache Web服务器不允许我刷新/左右,但在本地主机上其工作罚款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:29