Dynadot โ€” .com Registration $8.99

[Resolved] .htaccess Problems

Spacemail by SpaceshipSpacemail by Spaceship
Watch

Rudy

Established Member
Impact
16
.htaccess Problems

Hey guys,
I've just added a .htaccess file to my website for the first time a couple days ago. I'm doing quite a bit of work and research on SEO for the first time in a long time (ever?) and am learning quite a bit. Anyway, one thing I wanted to do was redirect requests coming for http://domain.com TO http://www.mydomain.com.

It is working. To an extent.

Since I have uploaded the .htaccess file, every time I go to http://domain.com/directory, I am taken to my 404 Error Page. But, of course, when I go to http://www.domain.com/directory, I am taken to where I want to go.

My culprit lies somewhere in here, at the top of my .htaccess file. I copied pretty much all of this code from some tutorials, etc... I've read on the internet. Here's what I've got:

<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]
ErrorDocument 404 /error404.php

By the way, do I need to run "RewriteEngine on" everytime I want to "rewrite" something? For example, I read a tutorial that gave some code to prevent a lot of the well known "black" bots from gaining access to my website. I decided to go ahead and include that. So underneath the last line you see here, I have "RewriteEngine on" again, and a LOT of rewritecond, checking to see if the bot should have permission or not.

Here's the first and last line of that:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
etc... etc... etc...
RewriteRule ^.* - [F,L]
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
what happens if you include the URI and L option here:

change:
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]

to:
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L]

and AFAIK, you only need to put RewriteEngine on once, before the rewrites.
 
0
•••
I think that seems to do the trick. I've tested it on a couple different directories, and it's working just fine. Thanks for the help!

I think part of it was also that one of the directories is password protected. Even now, I'm still getting the same problem when I try to go to that password protected directory. But for regular dirs, it works great - and that's what matters. I don't want to make that password protected directory easy to get in to anyway, obviously. :)
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back