简体   繁体   English

htaccess重定向子目录,但index.php除外

[英]htaccess Redirect sub directories except index.php

I have a htaccess file in www.mydomain.com/dir. 我在www.mydomain.com/dir中有一个htaccess文件。

I want to redirect requests from www.mydomain.com/dir/* to www.mydomain.com/dir except www.mydomain.com/dir/index.php 我想将请求从www.mydomain.com/dir/*重定向到www.mydomain.com/dir,但www.mydomain.com/dir/index.php除外

I tried this: 我尝试了这个:

RewriteEngine on
RewriteCond DOCUMENT_ROOT/ !-f
RewriteRule ^/*$ index.php

What am I doing wrong? 我究竟做错了什么?

This should probably work: 这可能应该工作:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /dir/

RewriteRule (?!^index\.php$)^.+$ index.php [L,NC]

That works almost! 差不多了!

www.mydomain.com/dir/.htaccess: www.mydomain.com/dir/.htaccess:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /dir/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (?!^index\.php$)^.+$ index.php [L,NC]

But when I access any file or sub directory in dir I get 404. The index.php is located in dir and any request to file or sub directory in dir should be redirected to dir/index.php . 但是,当我访问任何文件或子目录的目录 ,我得到404 index.php文件位于目录目录到文件的任何请求或子目录应该被重定向到目录/ index.php文件

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

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