[英]Permanent redirect to subfolder with .htaccess
I'm setting up a Symfony2 project on a Shared Host and I'm having some issues getting things done. 我正在共享主机上设置一个Symfony2项目,我遇到了一些问题。 Symfony2 by default has their dispatch controllers or main files (what in many system is the file
index.php
) inside /web
directory so if I move all the project to public_html
on the shared hosting then it won't works until I append the /web
to the end on the URL. Symfony2默认情况下它们的调度控制器或主文件(许多系统中的文件是
index.php
)在/web
目录下,所以如果我将所有项目移动到共享主机上的public_html
那么它将无法工作,直到我追加/web
到URL的末尾。 This is bad and noise for users since they know the page for it's domain. 这对用户来说是坏的和噪音,因为他们知道它的域的页面。 I'm trying to make the redirect using
.htaccess
as follow: 我正在尝试使用
.htaccess
进行重定向,如下所示:
//301 Redirect Entire Directory
RedirectMatch 301 /(.*) /web/$1
//Prevent directory listings
Options All -Indexes
But it's not working since the hosting said that this lines are bad in the .htaccess file, then how I can get ride of this problem? 但它没有工作,因为托管说这条线在.htaccess文件中不好,那么我怎么能解决这个问题呢?
In root .htaccess you can use this mod_rewrite
rule: 在root .htaccess中,您可以使用此
mod_rewrite
规则:
//Prevent directory listings
Options All -Indexes
RewriteEngine On
RewriteRule ^((?!web/).*)$ /web/$1 [L,NC,R=301,NE]
You know when you buy some hosting and you make your first FTP to it in your favourite client? 你知道什么时候你买了一些托管,你在你最喜欢的客户端制作了第一个FTP吗?
You might see something like this: 你可能会看到这样的事情:
/
ftp/
httpdocs/
access_log.txt
The web/
directory is the httpdocs/
in this scenario. web/
目录是此场景中的httpdocs/
。 Sometimes the directory is called public_html
, www
, or just html
. 有时目录名为
public_html
, www
或html
。
They are all the same thing in the end of the day. 他们在一天结束时都是一样的。
In your symfony project, the app/
, src/
, vendor/
directories are supposed to sit behind the public root directory. 在你的symfony项目中,
app/
, src/
, vendor/
目录应该位于公共根目录之后。
Normally on controlled servers you can create virtual hosts where you specify the document root. 通常,在受控服务器上,您可以创建指定文档根目录的虚拟主机。 However if you are trying to get a website uploaded, move everything up to the parent directory and rename the web directory to what server is set up to use.
但是,如果您尝试上传网站,请将所有内容移至父目录,并将网络目录重命名为设置使用的服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.