简体   繁体   English

根目录中带有index.php和htaccess的url路由

[英]url routing from root with index.php and htaccess in sub-directory

I'd like to know if it is possible to do this: 我想知道是否可以这样做:

To keep the root clean of all files, I want to put everything under a sub-directory (index.php, .htaccess,...). 为了保持所有文件的根目录干净,我想将所有内容放在一个子目录下(index.php,.htaccess等)。 Is it possible to configure a rule in .htaccess which resides in this sub-directory to redirect from root directory to index.php which also resides in the sub-directory ? 是否可以在位于此子目录的.htaccess中配置规则,以从根目录重定向到也位于该子目录的index.php?

Then what would be the syntax for .htaccess ? 那么.htaccess的语法是什么?

No. The rules in the subdirectory will only be used if a request is mapped to a path that includes said subdirectory. 否。仅当请求映射到包含该子目录的路径时,才会使用子目录中的规则。

To achieve this, you would have to put a rewrite rule either in httpd.conf or in the parent directory. 为此,您必须将重写规则放在httpd.conf或父目录中。

A .htaccess file has effect only in/on : .htaccess文件仅在以下位置有效:

  • The directory that contains it 包含它的目录
  • The sub-directories of that directory. 该目录的子目录。

So, no, you cannot have a .htaccess in a directory, that will impact what's in it's parent directory : Apache will not even see that .htaccess file. 因此,不,您不能在目录中使用.htaccess ,这会影响其父目录中的内容:Apache甚至不会看到该.htaccess文件。


If you want something like that, you'll have to put it at a higher-level ; 如果您想要这样的东西,则必须将其放在更高的层次上。 either : 要么:

  • In a .htaccess file in the parent-directory (which you don't want to do, it seems) 在父目录的.htaccess文件中(似乎您不想这样做)
  • Or directly in Apache's configuration -- in the configuration of your VirtualHost, for example. 或直接在Apache的配置中-例如,在VirtualHost的配置中。

只需将DocumentRoot更改为httpd.conf中的其他目录,或/ etc / apache2 / sites-available / your-site或类似的目录

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

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