Apache虚拟主机.htaccess和反应路由器

时间:2016-03-19 04:08:16

标签: windows apache .htaccess reactjs virtualhost

我正在运行带有apache 2.4的Windows 10机器。我正在尝试将我的网站部署到我的apache网络服务器,但路由无效。

例如,当我转到http://my.domain.com/时,我看到网站根目录。但是当我尝试去http://my.domain.com/users时,我收到404错误。

我正在使用虚拟主机来运行我的网站,因此它不会干扰我的主域名。

以下是我的设置:

React redux routing:

ReactDOM.render(
  <Provider store={store}>
    <Router history={browserHistory}>
      <Route component={App}>
        <Route path="/" component={HomePage} />
        <Route path="/users" component={UsersPage}/>
        <Route path="/user" component={UserPage}>
          <Route path="/user/:id" component={UserPage}/>
        </Route>
        <Route path="*" component={NotFoundPage}/>
      </Route>
    </Router>
  </Provider>,
  document.getElementById('app')
);

htaccess的:

RedirectMatch ^/oauth2/redirect/(.*)$ $1

<ifModule mod_rewrite.c>


  #######################################################################
  # GENERAL                                                             #
  #######################################################################

  # Make apache follow sym links to files
  Options +FollowSymLinks
  # If somebody opens a folder, hide all files from the resulting folder list
  IndexIgnore */*


  #######################################################################
  # REWRITING                                                           #
  #######################################################################

  # Enable rewriting
  RewriteEngine On
  RewriteBase /

  # If its not HTTPS
  # RewriteCond %{HTTPS} off

  # Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
  # RewriteCond %{HTTP:X-Forwarded-Proto} !https

  # Redirect to the same URL with https://, ignoring all further rules if this one is in effect
  # RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]

  # If we get to here, it means we are on https://

  # If the file with the specified name in the browser doesn't exist
  RewriteCond %{REQUEST_FILENAME} !-f

  # and the directory with the specified name in the browser doesn't exist
  RewriteCond %{REQUEST_FILENAME} !-d

  # and we are not opening the root already (otherwise we get a redirect loop)
  RewriteCond %{REQUEST_FILENAME} !\/$

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


  # Rewrite all requests to the root
  RewriteRule ^(.*) /

</ifModule>

的httpd-vhosts.conf

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin myemail@nbnet.nb.ca
    DocumentRoot "D:/my.domain.com"
    ServerName my.domain.com
    ServerAlias mystify.homenet.org
    ErrorLog "logs/my.domain.com-error.log"
    CustomLog "logs/my.domain.com--access.log" common
    <Directory "D:/my.domain.com">
        Options FollowSymLinks
            AllowOverride All
            Order allow,deny
            allow from all 
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin myemail@nbnet.nb.ca
    DocumentRoot "D:/my.domain.com/lln4"
    ServerName lln.domain.com
    ErrorLog "logs/lln.domain.com-error.log"
    CustomLog "logs/lln.domain.com-access.log" common
    <Directory "D:/my.domain.com/lln4">
        Options FollowSymLinks
        Options All
        Include D:/my.domain.com/lln4/.htaccess
            AllowOverride All
            Order allow,deny
            allow from all 
    </Directory>
</VirtualHost>

任何人都知道为什么我网站的子页面无效?

0 个答案:

没有答案