Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 使用AliasMatch和/或htaccess将url重定向到子文件夹_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 使用AliasMatch和/或htaccess将url重定向到子文件夹

Apache 使用AliasMatch和/或htaccess将url重定向到子文件夹,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有以下设置,我的域名(假设abc.com)指向src src index.php blog index.php 我想将所有请求重定向到abc.com/blog,以便从src/blog文件夹获得服务,其余请求从src文件夹获得服务。src和blog都有其他目录,并且都使用路由到index.php来服务页面 问题是像abc.com/blog/which这样的URL会转到src/index.php,而它应该转到blog/index.php 编辑src/.htacce

我有以下设置,我的域名(假设abc.com)指向src

src
    index.php
    blog
        index.php
我想将所有请求重定向到abc.com/blog,以便从src/blog文件夹获得服务,其余请求从src文件夹获得服务。src和blog都有其他目录,并且都使用路由到index.php来服务页面

问题是像abc.com/blog/which这样的URL会转到src/index.php,而它应该转到blog/index.php 编辑src/.htaccess无效,因为我必须将请求定向到子目录。 下列事项:

AliasMatch  /blog.* /path/to/blog
导致循环重定向: abc.com/blog/whatever/index.php/index.php/index.php

我按照这里的解释:

它说,如果我们在alias target中给出一个目录路径,Apache将添加index.php

要求很简单:只需将所有blog/*请求扔到blog文件夹中,htaccess就可以处理其余的请求


<Directory /usr/local/www/apache>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]

    RewriteRule ^blog/.*$ /blog/index.php [NC,L]
    RewriteRule ^.*$ /index.php [NC,L]
</Directory>
重新启动发动机 RewriteCond%{REQUEST_FILENAME}-s[或] RewriteCond%{REQUEST_FILENAME}-l[或] RewriteCond%{REQUEST_FILENAME}-d 重写规则^.*$-[NC,L] 重写规则^blog/*$/blog/index.php[NC,L] 重写规则^.*$/index.php[NC,L]

我把它放在apache配置文件中。我已经扔掉了别名匹配和.htaccess文件。

/blog/.htaccess
中尝试此规则作为您的第一条规则:

RewriteRule ^(.*)$ /src/$1 [L]

不起作用。。。abc.com/blog/whatever仍会转到src/index.php
abc.com/blog/whatever
应根据此转到
abc.com/src/blog/whatever
。此.htaccess中是否还有其他规则,或者
/blog/
文件夹中是否有.htaccess?blog使用url重写并拥有自己的htaccess。“whatever”不是一个目录-它应该转到blog/index.php,但不是-这是我遇到的主要问题。好的,从
/blog/
文件夹发布你的.htaccess。仍然不工作。。。我现在得到以下错误:在这个服务器博客的htaccess上找不到请求的URL/src/是一个标准的wordpress访问:
RewriteBase/RewriteRule^index\.php$-[L]RewriteCond%{REQUEST\u FILENAME}-f RewriteCond%{REQUEST_FILENAME}-重写规则/index.php[L]
不起作用。。。abc.com/blog/which仍然会转到src/index.php而不是blog/index.php