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?
elepilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bigeven2002Commented:
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?
0
elepilAuthor Commented:
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?
0
bigeven2002Commented:
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.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

bigeven2002Commented:
Also, check in your httpd.conf file at the end of it is this listed?
<IfModule mod_rewrite.c>
RewriteEngine On
LogLevel warn mod_rewrite.c:trace4
</IfModule> 

Open in new window


So I think this will output the data to c:\xampp\apache\logs\rewrite.log, or wherever the error.log is listed.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
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.
0
elepilAuthor Commented:
Once again, thank you for your help, bigeven2002!
0
bigeven2002Commented:
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.
0
bigeven2002Commented:
Glad I could help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.