Update 02
Hi all,
After much searching I found a very good clue that helped me take some important steps towards my goal. Everything is now working well except for the following:
I need to ReWrite or ReDirect to www.domain.com/go404 in these cases:
www.domain.com
www.domain.com/
domain.com
domain.com/
But not, of course, when they type
www.domain.com/subdomain or
domain.com/subdomain
Presently, my htaccess code has this snippet added:
# This sends "just domain" visits to 404
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/go404 [R=301,L]
# This one makes a NON WWW become a WWW
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
# This strips the trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
Can anyone tell me how to set up the condition so it ONLY allows domains written without the trailing slash and/or subfolder string? As indicated above those should redirect to 404.
Thanks!
Update from my original question:
Hi guys, I tried the solution offered but it doesn't work. To recap:
I'm trying to get our Magento site to respond as in the table below using .htaccess rewrites. For whatever reason, only some options work (marked as "Ok"). The others produce www.domain.com, that I don't want (marked as "Fail").
When visitor types The (internal) result should be:
--------------------------- -------------------------------------
www.domain.com www.domain.com/go404 (Fail)
www.domain.com/ www.domain.com/go404 (Fail)
www.domain.com/notfound www.domain.com/go404 (Ok)
www.domain.com/subdomain www.domain.com/_subdomain (Ok)
www.domain.com/subdomain/ www.domain.com/_subdomain (Ok)
www.domain.com/admin www.domain.com/admin (Ok)
domain.com www.domain.com/go404 (Fail)
domain.com/ www.domain.com/go404 (Fail)
domain.com/notfound www.domain.com/go404 (Fail)
domain.com/subdomain www.domain.com/_subdomain (Fail)
domain.com/subdomain/ www.domain.com/_subdomain (Ok)
domain.com/admin www.domain.com/admin (Fail)
To keep things in order in our Root, all subdomains are folders called _subdomain. Visitors to the site only have to write www.domain.com/subdomain and we add the underscore in front.
Notes:
"notfound" is any string without a corresponding "_subdomain" folder
"admin" is a valid exception: no underscore in front
As you can see from the table above all addresses without the "www" fail. Also, I have two specific problems related to the "clean" domain + clean domain with trailing slash.
This is my complete htaccess (I erased the comments to make it shorter):
addhandler x-httpd-php5-cgi .php5
addhandler x-httpd-php5-cgi .php
addhandler x-httpd-php-cgi .php4
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_php5.c>
php_value memory_limit 256M
php_value max_execution_time 18000
php_flag magic_quotes_gpc off
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
php_flag zend.ze1_compatibility_mode Off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_deflate.c>
</IfModule>
<IfModule mod_ssl.c>
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type=$1 [QSA,L]
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
AddDefaultCharset Off
<IfModule mod_expires.c>
ExpiresDefault "access plus 1 year"
</IfModule>
Order allow,deny
Allow from all
<Files RELEASE_NOTES.txt>
order allow,deny
deny from all
</Files>
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^domain\.com/(admin)$ www.domain.com/$1 [L]
RewriteRule ^/(.*)$ www.domain.com/_$1 [L]
RewriteRule ^www\.domain\.com/(admin)$ www.domain.com/$1 [L]
RewriteRule ^www\.domain\.com/(.*)$ www.domain.com/_$1
Thanks to all
Old question:
I'm trying to get our site to respond in this way using .htaccess rewrites. For whatever reason, only one of the options works (marked as "Ok") and all of the others produce www.domain.com (marked as "Fail").
I need to achieve this combination:
When visitor types The (internal) result should be:
----------------------------- --------------------------------
www.domain.com www.domain.com/go404 (Fail)
www.domain.com/ www.domain.com/go404 (Fail)
www.domain.com/subdomain www.domain.com/_subdomain (Ok)
www.domain.com/admin www.domain.com/admin (Ok)
domain.com www.domain.com/go404 (Fail)
domain.com/ www.domain.com/go404 (Fail)
domain.com/subdomain www.domain.com/_subdomain (Fail)
domain.com/admin www.domain.com/admin (Fail)
My (root) .htaccess file has this:
RewriteRule ^/(admin) www.domain.com/$1
RewriteRule ^/(.*) www.domain.com/_$1 [L]
I tried forcing domain.com into www.doman.com with
RewriteRule ^domain.com$ www.domain.com (Fail)
Btw: the subdomain folder (_subdomain) also has an .htaccess file. Do I need to add RewriteRule there too? I tried with/without to no avail.