I have a shared web hosting account. I want to be able to access the mod_rewrite log, but I don't have access to httpd.conf file. Can I do it using .htaccess? (Apache is version 1.3, under Linux) How else to debug a .htaccess that doesn't do redirects I expected? Is any way to find out what is the result of the Rewrite rule?
Rewrite Logs are quite difficult to read, especially if you are doing this on a live server and have multiple concurrent requests. It generally easier to debug rewrite rules in other ways. The first technique I would suggest is adding [R] after the rule. This will turn it into a redirect (302 response code) which will show exactly what final URL is being requested in your browser's address bar. The most common problem is that the rule you think should match a URL is not matching but another one below it in the file is matching. Another, slightly less common problem is when a rule matches different parts of the URL than what you thought it would match. (.*) is particularly dangerous for this. A technique to determine which rule is matching is to create a rule: RewriteRule .* http://google.com [R] Code (markup): which you place as the first line in your .htaccess file. After each request of the page you want, you move it down one line until it no longer matches (i.e you are no longer redirected to google.com) The rewrite rule above the google rule is the one that matches.
How about the lines below? I use the [R], but the address bar doesn't change and Apache answers (after about 2 minutes - I believes it enters in a loop) with: "Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Apache/1.3.33 Server" I try to access http://mydomain/test-1 My .htaccess looks as following: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ main.php?page=$1 [R]
Add this in instead: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^main.php RewriteRule ^(.*)$ main.php?page=$1 [R]