The 'matching any directory' thing isn't a huge deal, since nobody should be accessing any directory at all - so that's one reason why I put that line in the way it is. Unfortunately, if I use your option:
- Code: Select all
# Check to see if this is requesting the homepage
RewriteRule ^$ /siteDyn/ [E=REQUEST_URI:siteDyn/index.php,NE,L]
# End homepage check
That matches only /site/ not without a trailing slash, so it won't redirect
http://www.generic.edu/site to the homepage (although it works if there is a trailing slash). Since my method works for all possible directories, I put it that way. I did a lot of reading on how to add trailing slashes and tried putting an .htaccess into the root directory, but that didn't seem to work.
When I try your method, all I get is 404 errors. I did some checking around and one thing that you have in your posts is 'SCRIPT_FILENAME' which when I attempt to print that off using a variable dump always returns an empty string. That is one reason why I ended up going with REQUEST_FILENAME which actually had a value.
Your beginning slash suggestion was very, very obvious and I'm glad you pointed it out. It makes the code much smoother. The suggestion of turning of MultiViews also worked marvelously. Thanks!
Below you will find my current two .htaccess files as they stand.
/site/.htaccess
- Code: Select all
Options +FollowSymLinks
Options -Multiviews
RewriteEngine On
# Check to see if requested cached file exists, return it.
RewriteCond %{REQUEST_FILENAME}.gz -f [NC]
RewriteRule ^(.*)$ - [L]
# End of cache check
# Check to see if this is requesting the homepage
RewriteCond %{REQUEST_FILENAME}/ -d
RewriteRule ^(.*)$ /siteDyn/ [E=REQUEST_URI:/siteDyn/index.php,NE,L]
# End homepage check
# Redirect to Joomla Dynamic site
RewriteRule ^(.*)$ /siteDyn/$1 [E=REQUEST_URI:/siteDyn/$1,NE,L]
# End of redirection
Full /siteDyn/.htaccess (I'm using Joomla!, so the end is straight from there)
- Code: Select all
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
###CHANGE ENV VARS IF REDIRECT
RewriteRule .* - [E=REQUEST_URI:%{REDIRECT_REQUEST_URI},NE]
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)
# RewriteBase /
########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
Note that the line preceded by ###CHANGE ENV VARS IF REDIRECT is the only line that I have added myself. The rest is default Joomla! CMS.
Within the Joomla! index.php file, I have added the following:
- Code: Select all
$_SERVER['REQUEST_URI']=isset($_SERVER['REDIRECT_REDIRECT_REQUEST_URI'])?$_SERVER['REDIRECT_REDIRECT_REQUEST_URI']:$_SERVER['REQUEST_URI'];
There's the whole story from beginning to end. I have nothing in my .htaccess file in my root directory. Still not sure why the shorthand code you gave for the homepage doesn't work, but things seem to be fairly lean at this point.
Justin