简体   繁体   中英

Don't rewrite particular subfolder

I'm using the following .htaccess to rewrite all URLs to my index.php file if they're not actual files or folders:

Options +FollowSymLinks
RewriteEngine On

// This bit redirect www.mydomain.com to mydomain.com
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

// This bit redirects all requests to index.php if a file or directory
// bearing that name doesn't exist
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php

I'm now adding an admin section to my website and I would like to not rewrite this particular URL:

mydomain.com/admin

I would like that case to be treated as it would be by default (in this case defaulting to mydomain.com/admin/index.php )

I've attempted to figure this out by myself but regex is still alien to me...

You can use:

Options +FollowSymLinks
RewriteEngine On

// This bit redirect www.mydomain.com to mydomain.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NE]

// This bit redirects all requests to index.php if a file or directory
// bearing that name doesn't exist OR it doesn't start with /admin/
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^admin/ ./index.php [L,NC]

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