Forum Moderators: phranque
So how do I make non-www pages that are within the cgi-bin return a 404 if they do not exist?
If I take the www redirect out, I get the 404 so can I do it by making my www redirect not apply to pages within the cgi-bin? Something like that...or?
This is all I have now:
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Thank you!
A server response header of 304 is not "Found" but rather, "Not Modified", unless you meant you got a "302-Found" instead of "304-Not Modified" (these details deserve a lot of care, since they can greatly affect the diagnosis).
You can exclude your cgi-bin files from the "www" redirect using a RewriteCond with a negative-match pattern on %{REQUEST_URI}, e.g.
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{HTTP_HOST} ^example\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com\. [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com\:[0-9]+
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Hi Jim,
Oops, you're right I meant 304 not modified.
I did not set up the cgi-bin directory, it's set up by my host.
Okay, I tried the code that you gave me (thank you!) and it works as far as accessing a non-www page that is there.
But if I try to get a non-www page that is not there it still does a 301 to my 404 page.
If I try to get a page that is not there but WITH the www everything works fine.
If I take out the www redirect code from my htaccess file, everything works fine.
And I see I made another mistake with what I said the first time, there is actually more in my htaccess file. It looks like this:
# Remove multiple slashes anywhere in URL
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . http://www.example.com%1/%2 [R=301,L]
#
# Remove trailing slash if filetype present in URL
RewriteRule ^(.+\.[^/]+)/$ http://www.example.com/$1 [R=301,L]
# Remove extra URL-path info if filetype present in URL
RewriteRule ^([^.]+\.[^/]+)/ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{HTTP_HOST} ^example\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com\. [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com\:[0-9]+
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
ErrorDocument 404 /404.html
#
Any ideas?