简体   繁体   English

silex,.htaccess,虚拟主机不起作用

[英]silex, .htaccess, webhosting doesn't work

Here's my file .htaccess on local machine and web hosting, on local everything works well, but on web-hosting i can access web/index.php only like example.com/web/index.php 这是我在本地计算机和Web托管上的.htaccess文件,在本地一切正常,但是在Web托管上,我只能像example.com/web/index.php一样访问web / index.php

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteBase /web/index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>

Your RewriteBase is not correct, you should put only the directory, not the file name. 您的RewriteBase不正确,您应该只放置目录,而不是文件名。 Also if your root project is the web project, your rewrite base should be only / and in the rewrite rule you should tell apache were to redirect all of your requests. 同样,如果您的根项目是Web项目,则您的重写基础应该仅为/,并且在重写规则中,您应该告诉apache重定向所有请求。 So, you should use something like: 因此,您应该使用类似:

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.*$ /web/index.php [QSA,L]
</IfModule>

But keep in mind that only your web folder must be publicly accessible, not your entire project. 但是请记住,只有您的Web文件夹必须可以公开访问,而不是整个项目。 You should change that if you can (otherwise you should put an .htaccess file in the root project and another in the web folder, but this is beyond the scope of your question). 如果可以,您应该更改它(否则,应将.htaccess文件放在根项目中,并将另一个放在Web文件夹中,但这不在您的问题范围内)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM