简体   繁体   中英

htaccess redirect won't work if file doesn't exist

Server: Debian with apache2;

var/www: project -> /samba/project/

samba/project: index.php .htaccess test.php

htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /project/

RewriteCond %{REQUEST_URI} !index.php.*
RewriteRule ^(.*)$ index.php [L]

localhost/ -> it works

localhost/index.php -> it works

localhost/test.php -> it works (redirect to index.php works)

http://localhost/asdsads -> doesn't work (error 403)

why?

thx

Try changing your last two lines to

RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^ index.php [L]

The first line checks if the requested URL does not map to a physical file, and the second line rewrites every request (which always has a beginning, denoted by ^) to 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