Forum Moderators: phranque
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $2 !^projects/([^/]*?)/(index\.php¦assets¦robots\.txt¦favicon\.ico¦readme\.txt¦temp)
#RewriteCond /projects/$1 -F
RewriteRule ^projects/([^/]+)(.*)$ /projects/$1/index.php/$2 [L]
</IfModule> See the commented out line? Let's say I have two URLs:
/projects/a
/projects/b
a is a physical folder that exists, b does not exist. I'm trying to get it so:
/projects/a/somecontroller/someparam goes to:
/projects/a/index.php/somecontroller/someparam
AND
/projects/b/<anything here> goes to a 404.
Any pointers?
RewriteEngine On
#
# if not an exempted final URL-path-part
RewriteCond $2 !^(index\.php¦assets¦robots\.txt¦favicon\.ico¦readme\.txt¦temp)
# if requested URL-path does not resolve to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# if requested URL-path does not resolve to an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# if document_root+/projects/<subdirectory>/index.php exists
RewriteCond %{DOCUMENT_ROOT}/projects/$1/index.php -f
# then rewrite /projects/<subdir>/<name> to /projects/<subdir>/index.php/<name>
RewriteRule ^projects/([^/]+)/(.*)$ /projects/$1/index.php/$2 [L]
"RewriteBase /" is the default, and a waste of time unless you previously set it to something else and need to set it back.
Always put RewriteConds for -d, -f, etc. filesystem checks and reverse-DNS lookups *last* in the set of RewriteConds whenever possible -- all are *very* resource-intensive, and should not be done unless all other conditions have been checked first, and it is determined that these additional checks are actually required. Understand that the code posted here will make three calls to the operating system's filesystem, invoking thousands of lines of server code. In addition, if the filesystem state is not cached, this could results in up to three read operations on the physical disk for each request that matches the rule pattern and passes the preceding RewriteConds. This kind of thing is known to force early and otherwise-unnecessary server upgrades...
Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.
Jim