简体   繁体   中英

htaccess Redirect sub directories except index.php

I have a htaccess file in www.mydomain.com/dir.

I want to redirect requests from www.mydomain.com/dir/* to www.mydomain.com/dir except 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:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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