编程语言
首页 > 编程语言> > php – 使用htaccess将root重定向到子文件夹而不在URL中显示

php – 使用htaccess将root重定向到子文件夹而不在URL中显示

作者:互联网

我目前在共享服务器上使用Silex framework托管一个网站,我有一个问题…

Silex就像是Synfony,有一个位于/ web /子文件夹中的app.php文件:该网站只能通过URL website.com/web/访问.我无法创建虚拟主机,因为它是共享服务器,所以我认为解决方案是使用.htaccess文件…

我设法将website.com自动重定向到website.com/web/,但我真的不喜欢这个选项;我宁愿website.com直接指向website.com/web/,但我不知道如何通过使用htaccess文件来做到这一点.我一直试图解决这个问题好几个小时,它正在杀了我……

目前我使用这个文件:

<IfModule mod_rewrite.c>
    Options -MultiViews

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

但它只是将您从website.com重定向到website.com/web

无论如何我可以让根URL直接指向带有htaccess文件的/ web文件夹?

非常感谢你 :)

解决方法:

如果您只想输入http://example.com来访问http://example.com/subdirectory,这应该可行.

# .htaccess main domain to subdirectory redirect 

RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/subdirectory/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$/subdirectory/$1 
# Change example.com to be your main domain again. 
# Change 'subdirectory' to be the directory you will use for your main domain 
# followed by / then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$subdirectory/ [L]

标签:shared-hosting,htaccess,php,apache,mod-rewrite
来源: https://codeday.me/bug/20190831/1775811.html