Symfony2 - redirect /web directory to root

為{幸葍}努か 提交于 2020-01-01 04:36:08

问题


I've got a duplicate content problem with my Symfony2 projet. The following urls gives the same content :

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

Here is the content of my /.htaccess file :

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

And the content of my /web/.htaccess file :

<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. Do you have any suggestion ?


回答1:


In the htaccess file in your web directory (the /web/.htaccess file), add these rules right beneath the 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.



来源:https://stackoverflow.com/questions/16054551/symfony2-redirect-web-directory-to-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!