Whole website redirecting to home page. Newbie help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

hoyaguru
Forum Newbie
Posts: 13
Joined: Fri Jul 08, 2011 3:57 pm

Re: Whole website redirecting to home page. Newbie help!

Post by hoyaguru »

Hmm, one more thing. I just tried a little experiment. I took the index.php file, which I know is working, copied it, and renamed the copy to test.php. I then uploaded test.php to the root directory, then typed in www.arizonaglassrepair .com/auto.php, and my browser immediately went to the glassking site. Why? It's the same exact file as the home page, which works perfectly, but by changing the name it is suddenly a redirect. This only confirms my suspicions that the other pages are fine.
hoyaguru
Forum Newbie
Posts: 13
Joined: Fri Jul 08, 2011 3:57 pm

Re: Whole website redirecting to home page. Newbie help!

Post by hoyaguru »

OK, it's about 3:00AM and I'm about to quit, and I just found one more piece of the puzzle...

In the root directory of arizonaglassrepair, there are several directories, and one directory is called arizonaglassrepair.com (so looking at it on my hard drive, it shows up as c:\arizonaglassrepair\arizonaglassrepair.com). In this folder are just about the same files as are in the root directory, an index.php, residential.php, .htaccess, and so on. I changed a couple of word in the index.php file in this directory and uploaded it, and it changed the home page online, so this has to be the real directory for arizonaglassrepair (arizonaglassrepair started out as a subdomain under glassking). The .htaccess file in this directory is just about the same as the one in the root directory, except that all of the url's are to arisonaglassrepair instead of glassking. There are the same two lines:

ErrorDocument 403 http://arizonaglassrepair.com/
ErrorDocument 404 http://arizonaglassrepair.com/

As you can see they are going to the arizonaglassrepair site instead of the glassking site. Now, when I first started trying to figure out this site, when I clicked on a link, it just stayed on the home page. I erased the two ErrorDocument lines, and then suddenly every time I clicked on a link, it would load the glassking home page. So, since the two lines were gone from this .htaccess file, I guess the site defaulted to look at the .htaccess file in the root directory, which is why the redirect changed. I just put the two lines back in, and the redirects are back to the arizonaglassrepair site.

I don't know if this will make things easier or harder to figure out for someone to help me, I figure the more info the better.
hoyaguru
Forum Newbie
Posts: 13
Joined: Fri Jul 08, 2011 3:57 pm

Re: Whole website redirecting to home page. Newbie help!

Post by hoyaguru »

This just keeps getting better...

So the home page has 5 links on it. Three at the top, which are residential, commercial, and auto, and two at the bottom, which are privacy-policy and arizona-glass-blog. In the same folder as the index.php are files corresponding to these links, residential.php, commercial.php, and so on. Four of the five links, when clicked on, would just reload the home page, but the last link, arizona-glass-blog, would actually take you to a new page, the actual arizona glass blog. I've been searching through files for two days trying to figure out what was different about this last link, and I just figured it out. There is a directory inside the home directory called arizona-glass-blog. I went into this folder, and there is an index.php file and some other files there, The index.php file has the exact same info in it that is in the arizona-glass-blog.php file. So, I created a new directory called residential, then I copied the residential.php file into this directory, renamed the file to index.php, clicked on the residential link on the home page, and the page came up. Did the same for commercial and auto, created their own directories, copied the php files into the directories, renamed them index.php, and they work fine.

Once again, I have no clue as to why this is happening. Without knowing a single thing about php, this is like a huge riddle to me, if anyone out there can either tell me what the heck is going on, or at least point me in the right direction, I'd really appreciate it.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Whole website redirecting to home page. Newbie help!

Post by twinedev »

Ok, finally had time to sit down and look things over....

At the end of your .htaccess file, you have this:

Code: Select all

RewriteCond %{THE_REQUEST} ^GET\ /([^/]+)\.php\ HTTP
RewriteRule ^([^/]+)\.php$ http://www.arizonaglassrepair.com/%1/ [R=301]

#this to add slash if end slash missing
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+)\ HTTP
RewriteRule ^([^/]+)\.php$ http://www.arizonaglassrepair.com/$1/ [R=301]
Which the first section says if you are requesting any file in the root directory that ends in .php (ie. http://www.arizonaglassrepair.com/test.php ) to rewite the request as the same thing WITHOUT the .php extension. (ie. http://www.arizonaglassrepair.com/test ) Note there was an earlier test to directly handle the index.php file.

The reason it works when you do http://www.arizonaglassrepair.com/test/index.php is because now that doesn't match the rules being set. Try replacing those last two with the following (and then get rid of the /residential/index.php etc)

Code: Select all

	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) /$1.php [L]
This says that if the item requested is NOT a file and NOT a directory and NOT /favicon.ico, then take it to the request, but add .php to the end of it.

Let me know if that works.

-Greg
hoyaguru
Forum Newbie
Posts: 13
Joined: Fri Jul 08, 2011 3:57 pm

Re: Whole website redirecting to home page. Newbie help!

Post by hoyaguru »

Greg,

Sorry for the delay in thanking you for your post. I got the site working by creating directories for each page, and the site owner was happy with that, and so I left well enough alone. I have your reply saved just in case I ever need to work on the site again, and I'll give it a try if that's the case. I really need to get a "php for dummies" book or something. I told the site owner that if he had hired someone who knew php, they probably would have fixed it in 5 minutes, it ended up taking me about 18 hours of trying all kinds of different things, until I found a back door kind of way to fix it. Now he's asking me how much he owes me. lol, it's hard to charge for something I did wrong and took way too long to do. He also has a list of stuff he wants me to do with another site. Oh boy...

Thanks again, I do appreciate your help.
Post Reply