Link to home
Start Free TrialLog in
Avatar of elepil
elepil

asked on

Question on debugging with mod_rewrite

Let's say my simple .htaccess file looks like this:

RewriteEngine On
RewriteBase /
RewriteRule ^login/*$ public/login.php [L]

Open in new window


To my understanding, if I used the URL of www.mySite.com/login, it should redirect to mySite/public/login.php. In my browser, it would say http://www.mySite.com/login (which is expected), but I'm getting an error saying "Object not found. The requested URL was not found on this server.", so it's evident to me that Apache couldn't find the page I'm asking it to redirect to.

However, in order for me to troubleshoot this, I need to know what URL Apache is trying to redirect to. How can I see what URL Apache is *actually* using?
Avatar of bigeven2002
bigeven2002
Flag of United States of America image

Hello,
Your code appears to be correct.  I tested it in my setup.  My concern is with the RewriteBase line.  Is / the correct path to the public folder?  The object not found may be because the public folder wasn't found in the directory that / points to.

If the public folder is within another subfolder, you would need to specify that in the line.  So if your webroot was / and the public folder was inside another folder called subfolder, then:
RewriteBase /subfolder/

Open in new window


Also, have you gone directly to the URL of /public/login.php to ensure that page loads normally?
Avatar of elepil
elepil

ASKER

To bigeven2002.

I think I was able to figure it out .. this time. My application's full path is:

C:\xampp\htdocs\myApp

And in that is the 'public' folder (i.e., C:\xampp\htdocs\myApp\public\login.php). But still, I know this won't be the last path-related issue I'll encounter, and I really want to know how to debug mod_rewrite issues like this. It would've been much easier for me to troubleshoot if I only knew what URL Apache was using when it issued the error.

Do you know a way of displaying the exact URL Apache is issuing?
Not sure of the exact answer on how displaying the URL.  Do you mean to review that in a log file which URL is being parsed when the /login is requested?

This may be a long shot, but you can try adding the lines below to your .htaccess file.  This may result in 500 error though.  Change the log path to the rewrite.log location on your system.

RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3

Open in new window

If your apache version is >= 2.4, then you might also need this line:
LogLevel alert rewrite:trace6

Open in new window


Or you can also try adding it to the virtual host file if that is accessible in xampp (change the path again)
<VirtualHost *:80>
  # ...

  RewriteLogLevel 8
  RewriteLog /var/log/apache2/rewrite.log

  # ...
</VirtualHost>

Open in new window


I wasn't able to fully test this so I don't know if it will work or not.  But theoretically, this will put the URL being parsed in the log file for debugging purposes which might give you what you're looking for.
ASKER CERTIFIED SOLUTION
Avatar of bigeven2002
bigeven2002
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elepil

ASKER

To bigeven2002.

RewriteLog "/var/log/apache2/rewrite.log does not work in .htaccess file. Do you know what file name contains the <VirtualHost *:80> is? I may have to do it in one of the config files.
Avatar of elepil

ASKER

Once again, thank you for your help, bigeven2002!
I honestly don't know which file has the virtual host setting, sorry.  I figured that might not work in htaccess but thought worth a try.  Let's skip the htaccess and virtualhost files and try the entry in the httpd.conf file above.
Glad I could help!