简体   繁体   中英

.htaccess RewriteEngine each URL

I want the .htaccess send each file/directory to my index.php . I have this so far:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} -d 

RewriteRule ^(.*)$ index.php?urlparam=$1 [NC,L] 


But this error apears on mysite.com/foobar , if directory exists:

Forbidden

You do not have permission to access this document.

If not:

Not Found

The requested document was not found on this server. (404)

Having both the !-f and -f set of conditions makes no sense. This is essentially saying:

Perform this rewrite rule if the request does not match an existing file and the request also matches an existing file.

Obviously, you can't have both.

What you want is simply:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ index.php?urlparam=$1 [NC,L] 

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