Forum Moderators: phranque
I've Google'd this to death, and tried many, many combinations ...
I'm redirecting all requests to a single PHP file (index.php). Images and files that exist are not redirected, but everything else is (including images that don't exist).
This works fine at the root of a directory (www.domain.com) and on subdomains (test.domain.com) but does not work in a preview environment (http://123.123.123.123/~domain/test/)
The index.php file works when called directly, or without any filename at all, and looking at the RewriteLog it appears to convert the filename - correctly - to the index.php location, but the browser returns 404 not found on the index.php file. It even lists the entire path of the file it can't find which is the correct location of the index.php file we want.
I've tried /index.php, index.php and /home/domain.com/public_html/test/index.php
I'm using cPanel, Apache 2 and PHP 5. And last, but not least, here's my .htaccess file
Options -Indexes +FollowSymLinksRewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-l
RewriteRule ^(.*)$ index.php [L]
Many thanks to anyone who can shed light on this PITA problem!
Regards
Mark
RewriteBase /~domain/test/above the RewriteConds, that might help.
If that does not help, you can post the relevant part of your RewriteLog on this forum. It is generally not a bad idea to check the normal server logs too, the error log for the exact error condition, and access log for the circumstances of this error.
Thanks for the replies.
The reason is does not appear to correlate is because it is the cPanel 'site preview'-type address; it allows us to see the site before it has fully propagated, or if it doesn't have an actual domain. The reason it is an issue is because I would like to be able to fully develop on these test sites, which use these strange URL's. The alternative, although cumbersome, is to create a subdomain on a regular (propagated) domain and develop on these, as that would be relative to / root.
Cheers for the help - I'll try using RewriteBase and see if that'll help at all.
Mark
Thanks for the suggestion. Using RewriteBase /~USERNAME/ worked like a treat. This doesn't figure, as the rewrite logs clearly state "Internal redirect with /home/domain.com/public_html/index.php which IS the correct file, and that doesn't work. Plus, the file it lists as being 404'd is that file also?! But, with that additional RewriteBase (even though /~USERNAME/ doesn't exist ANYWHERE on the filesystem; it's a rewritten or similar rule itself created by cPanel! lol) it works.
Perhaps the last point (about it being a redirect in itself) is the reason why it works. Either way - thank you for the suggestion. Now... why was I doing this in the first place after all? ;-)
This is the very situation the RewriteBase was made for, when the url(1) can not be determined based on the path(2).
url(1) is the address of your webpage, which can be anything, even a nonexistent resource, which is made with aliasing, rewriting, etc.
path(2) is the filesystem path, where the .htaccess files are taking place. So when working with url that are mapped in some way, you have to tell the rewrite engine which url you are working with, otherwise it try to "guess" it from the current path, which will fail in such a case.
You can read more about this in the mod_rewrite manual in the apache documentation.