Forum Moderators: phranque
I have a site that works fine using a .htaccess file that changes links so they are search engine friendly(symbolic links).
It looks something like this:
php_flag session.use_trans_sid off
RewriteEngine On
RewriteRule ^info/(.*).html$ page.php?pg=info&cont=$1 [L,NC] The 'pg' switch is setup like this:
case info:
include("inc/".$cont.".php");
break; So going to [site.com...] (which would take me to file.php located in the inc folder) it looks pretty like [site.com...]
This works fine on my current host, I have many redirects setup this way and they work fine.
My problem is that I uploaded the same files to the new host and it does not work - I get a 404 page error.
If I go to [site.com...] (my current host) I get a default IE "page cannot be displayed". If I go to [newsite.com...] (the new host) I get a 404 error.
I think my problem is that somehow the new site is seeing that a file doesn't exist before it hits the htaccess file so it kicks it out to a 404 page. I figured maybe if I changed it so that the symbolic link was going to an actual directory (http://www.site.com/inc/file.html) instead of (http://www.site.com/info/file.html) that it would work. But it still does not, I think this is because it sees file.html as an nonexistant file.
The only difference that I could see from the old server to the new server is that in phpinfo under "server api" the new server has "CGI" whereas the old server has "apache" though they both run apache.
The other odd thing is that if I include this in the .htaccess file "php_flag session.use_trans_sid off" it gives me a error 500 page.
I have talked to the host and there is no way to remove that 404 page, though I can use the .htaccess file to redirect it to my own.
I have looked through numerous threads and have seen a similar but not the same problem. I have added all kinds of info to the top of the .htaccess file...follow symbolic links..etc. etc. and it still doesn't work.
I am thoroughly stumped since this does work on another server. I do not big differences anywhere that could be causing this...except the 404 page which is my only explanation. Please help I'm driving myself nuts lol.
Welcome to WebmasterWorld!
First, go into IE's 'Options' and turn off 'show friendly' everything.
If you have 'Show friendly error messages' enabled, and if the 404 error page is smaller that 512 bytes, IE will show it's own 'friendly error page' and hide the complicated, mean-old scary 404 from you. This is to avoid upsetting Joe Average computer-user. Webmasters are allowed to modify these 'friendly' settings, and should... ;)
The fix is to create your own 404 error page, and make it larger that 512 bytes. Then add:
ErrorDocument 404 /local_path_to_your_404_page.html
This will correct the discrepancy between your servers -- They will both show their respective 404 error pages when you get a 404, and IE won't hide one from you.
Looking at your code, all I can see is that you may need to add the "Options" directive to it. You may also need to 'root' the page.php file as well:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^info/([^.]+).html$ /page.php?pg=info&cont=$1 [NC,L]
The change to the pattern just makes your rule run faster.
So, there are really two problems here. One is the difference in the size of the 404 page causing differences in the display of 404 errors between the two servers, and the other is that your rule isn't being executed.
If the above doesn't help, you may want to look into where the .htaccess file is located, and whether there's an Alias directive involved with your account's root directory path. If so, you may need to use RewriteBase to compensate for it. Look at your raw server error log after creating a 404 by testing your rule, and it will show you the requested URL-path. If it is not rewritten at all, that's one problem. If it's rewritten incorrectly, then examine the logged path to determine what went wrong and whether you need to use RewriteBase.
Jim
The working code..
Options +Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^info/([a-z]+)\.html$ /index.php?pg=info&cont=$1 [NC,L]
ones that still aren't working...
RewriteRule ^category/([a-z]+)\.html$ /index.php?pg=category&catinfo_id=$1 [NC,L]
RewriteRule ^products/([a-z]+)\.html$ /index.php?pg=productcats&product_id=$1 [NC,L]
The problem isn't an htaccess problem so much as it is a host problem. I won't mention them incase that isn't allowed but you get what you pay for with a cheap host I suppose.
Adding the additional 404 page would make that show up for nonexistant directories but not for the symbolic links...
The domain directories you need to manually create..I should have known it was bad news when I had to do that...because of that I needed to add and rewrite base as well.
I don't have access to logs, ssh, nothing...this leaves me with my hands tied when it comes to figuring out any kind of errors.
Thank you for your help, I spent 2 days driving myself crazy when its not really an .htaccess problem so much as it is a host problem - 99% of other hosts wouldn't have given problems like this. What you told me gave me enough info to get at least the one rule working so I know the others are possible...(not sure why but now it may just be a typo problem)
Thanks Again