开发者

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

I'd like to know if it is possible to do th开发者_运维问答is:

To keep the root clean of all files, I want to put everything under a sub-directory (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 ?

Then what would be the syntax for .htaccess ?


A .htaccess file has effect only in/on :

  • 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.


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)
  • Or directly in Apache's configuration -- in the configuration of your VirtualHost, for example.


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.


Just change your DocumentRoot to the different directory in httpd.conf, or /etc/apache2/sites-available/your-site, or similar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜