简体   繁体   English

Symfony2 - 重定向/ web目录到root

[英]Symfony2 - redirect /web directory to root

I've got a duplicate content problem with my Symfony2 projet. 我的Symfony2 projet存在重复的内容问题。 The following urls gives the same content : 以下网址提供相同的内容:

www.mywebsite.com/web/page and www.mywebsite.com/page www.mywebsite.com/web/pagewww.mywebsite.com/page

Here is the content of my /.htaccess file : 这是我的/.htaccess文件的内容:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

And the content of my /web/.htaccess file : 以及我的/web/.htaccess文件的内容:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

I would like to redirect any url starting with /web to / but I can't manage to do it. 我想重定向任何以/web开头的/web/但我无法做到。 Do you have any suggestion ? 你有什么建议吗?

In the htaccess file in your web directory (the /web/.htaccess file), add these rules right beneath the RewriteEngine On : 在您的Web目录中的htaccess文件( /web/.htaccess文件)中,在RewriteEngine On下方添加以下规则:

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /web/
RewriteRule ^(.*)$ /$1 [L,R=301]

This redirects all direct access to the web directory to the root. 这会将对Web目录的所有直接访问重定向到根目录。

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

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