子目录中的htaccess重定向到域

时间:2016-11-23 11:37:36

标签: php apache .htaccess redirect mod-rewrite

我使用的是最新版本的Slim Framework,我在网址重定向方面遇到了问题。

我的主要域名为somedomainname.com。我的文件夹中有一个名为santebarley的文件夹,所以我的网址已经是somedomainname.com/santebarley

santebarley文件夹是我的slim文件所在的位置。因此,我的somedomainname.com/santebarley/public位于公共文件夹中,因此最终路由为index.php.htaccess文件也位于公用文件夹中。

我可以访问index.php,但我的所有路由都会重定向到主域。

例如,我有这样的事情:

<a href="/">Click me</a>

不是转到somedomainname.com/santebarley/public,而是转到域robertsoriano.com或者我有类似

的内容
<a href="/something">Click me</a>

不是转到robertsoriano.com/santebarley/something,而是转到somedomainname.com

我真的不知道要编辑什么,因为这是我第一次编辑.htaccess文件。 .htaccess文件包含:

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

我之前一直在使用slim,虽然我想在子目录中测试它。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您需要使用以下规则在站点根目录(在another/santebarley/的父目录中)创建.htaccess:

RewriteEngine On

RewriteRule ^(?!another/santebarley/public/).*$ another/santebarley/public/$1 [L,NC]