PDA

View Full Version : htaccess redirect script not working



UncleChewie
05-19-2009, 11:48 PM
I found the knowledge base tutorial on writing an htaccess script that redirects mysite.com/subfolder to mysite.com, and I followed it and added a couple of tweaks I found searching these forums, but it doesn't work for me. I get a 500 error page. Here is a copy of the script I have now

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?trinitaretreat.com$ [NC]RewriteCond %{REQUEST_URI} !^/drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /drupal/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?trinitaretreat.com$ [NC]
RewriteRule ^(/)?$ drupal/index.php [L]

So, any ideas on where I went wrong and setting things right?

pghcollectibles
05-21-2009, 11:23 AM
im just throwing this out because no one else has answered yet

isn't this RewriteCond %{REQUEST_URI} !^/drupal/ supposed to be on its own line? and it doesnt have any flags []

and what is this ^(/)?$ actually saying?

UncleChewie
05-23-2009, 05:32 AM
I certainly don't know. I just copied this from the tutorial in the knowledge base. I don't actually understand it. Can you provide rewrite it and show me what you are proposing, and then I can see if it works?

pghcollectibles
05-23-2009, 10:03 AM
ok ^(/)?$ is looking for 0 or 1 instances of the forward slash following the domain name

one of my biggest problems has been not understanding the "pattern" and its synyax.

for just the reason the following forum said it was written:


"OK, now in english and maybe a little slower..."


So, learning first hand there was a need for basic, plain english defining of mod-rewrite, I decided to write a guide for those who would like to understand mod-rewrite without all the ultra-technical, "If you weren't a logic major, you can't use it," documentation that surrounds the subject. this (http://forum.modrewrite.com/viewforum.php?f=12) mod_rewrite forum seems to be the best i have found so far and i hope others will learn from it as i have.

also there doesnt have to be flags. (usually there are though)

so... make the condition i mentioned be on its own line and see what happens

UncleChewie
05-23-2009, 01:52 PM
Thank you for your advice.

Okay, I put the "RewriteCond %{REQUEST_URI} !^/drupal/" on it's own line and I'm still getting a 500 error.

pghcollectibles
05-23-2009, 09:38 PM
i dont see the error. is that the only lines of code in your .htaccess?

i dont know much about it so the best i can tell you is if you put a # in front of each line of code, it will act like a comment and not be parsed. so i would suggest doing it to one of the rules at a time (including the conditions)
like:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?trinitaretreat.com$ [NC]
RewriteCond %{REQUEST_URI} !^/drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /drupal/$1 [L]
#RewriteCond %{HTTP_HOST} ^(www.)?trinitaretreat.com$ [NC]
#RewriteRule ^(/)?$ drupal/index.php [L]or


RewriteEngine on
#RewriteCond %{HTTP_HOST} ^(www.)?trinitaretreat.com$ [NC]
#RewriteCond %{REQUEST_URI} !^/drupal/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /drupal/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?trinitaretreat.com$ [NC]
RewriteRule ^(/)?$ drupal/index.php [L]
then you'll know which rule is being affected, then you can remove the # from each condition, one at a time, save and check for the error.

are you sure its comming from .htaccess? try those above then if none of that gets rid of the error, try renaming .htaccess to htaccess.txt

if you still have the error, we will have to look elsewhere

UncleChewie
05-27-2009, 01:48 AM
Okay, I tried both of your above listed suggestions. And once again I get 500 errors. By the way, whenever I say that an attempt yields an error page, I mean that the error is found on both trinitaretreat.com as well as trinitaretreat.com/drupal. I don't know if that's of any importance.

pghcollectibles
05-27-2009, 10:21 AM
so let me get this correct. did you try renaming the file and still get the 500 error?

this would tell me its not in the .htaccess

a 500 error has to do with the server, so all sites would have the error.

i would check with live support before we go any further to see if they can see anything obvious from their end.

UncleChewie
05-27-2009, 12:06 PM
Oh, sorry, I didn't rename it, I just deleted it and the error went away. Same story with every attempt so far.

westpos0
03-10-2010, 01:39 AM
Do you have another .htaccess in the root (above your subdirectory) with the line RewriteEngine on? Instructions in one .htaccess file filter down to the subdirectories.

Most of the time duplicate RewriteEngine on lines will cause 500 errors. If you do have such an .htaccess file in the web root (above your subdirectory), comment out the line in the one in your subdirectory.


#RewriteEngine on