PDA

View Full Version : Debugging rewrite rules



dattas
07-19-2008, 10:22 AM
Are rewrite rules getting you down? they not working as you think they should? There is a way to help and it is called logging.

This requires editing the file located at /etc/httpd/conf/httpd.conf
If you are wanting to enable this for the primary domain then you will want to go to the very bottom of this file and find the Directive:

NameVirtualHost *:80
You will want to add the code listed below BEFORE the directive found above.

RewriteLog /var/log/httpd/rewrite_log
RewriteLogLevel 3

Mine now looks like:


RewriteLog /var/log/httpd/rewrite_log
RewriteLogLevel 3
NameVirtualHost *:80

then restart Apache, either by going to the Site Manager and using the Restart Account option or executing
apachectl restart from a shell.

If you want to add this to a subdomain or a secondary domain, find the correct virtal host entry and before the closing tag for the virtual host, put those two lines in, so if I needed this for my blog then I would change the virual host entry to look like:


<VirtualHost *:80>
ServerName blog.dattasmoon.com
ServerAlias www.blog.dattasmoon.com
DocumentRoot /var/www/blog
RewriteLog /var/log/httpd/blog_rewrite_log
RewriteLogLevel 3
</VirtualHost>

The reason I used /var/log/httpd/blog_rewrite_log instead of /var/log/httpd/rewrite_log is so the blog would log to a different file so I could look at the entries easier.

Restart apache and you are done, logging for all of the rewrite rules that are driving you crazy, just make sure to add the files to the /etc/logrotate.conf or delete the entries after you are done, these logs will get big fast!

Do you have an application you would like me to write a tutorial on how to install? PM me!
Get a question? just reply below!

roadside
11-08-2008, 06:44 PM
:o I've tried all of the suggestions on this forum, entered numerous code variations for the rewrite rules, but still cannot prevent image hotlinking with an .htaccess file.

I added a script to confirm that mod rewrite is working and contacted Westhost to make sure it was active on all my subdomains. It appears to be functioning. Still, no luck.

I followed your instructions to add the rewrite logging but am not really sure what I am looking for (see log entry below). I have spent a few hours on this and have reached the point of either pulling my hair out or abandoning the project altogether. I have opted to move on to something else, as I don't have any hair that I can spare at the moment.

Any other suggestions on how I can get hotlinking .htaccess rules to work?

.... [per-dir /var/www/html/] strip per-dir prefix: /var/www/html/fm/FileManager/FileManager.cgi -> fm/FileManager/FileManager.cgi
.... [per-dir /var/www/html/] applying pattern '\.(jpg|jpeg|png|gif)$' to uri 'fm/FileManager/FileManager.cgi'
.... [per-dir /var/www/html/] pass through /var/www/html/fm/FileManager/FileManager.cgi

wildjokerdesign
11-09-2008, 06:57 AM
The log indicates that it is working. What is your .htaccess file? What do you expect the .htaccess file to do?

roadside
11-09-2008, 04:31 PM
I'm trying to block hotlinking. Maybe there is something specific to a virtual server that I am missing? Or, should it not make any difference? Here is the code for the .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?legendary.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

-Mike

wildjokerdesign
11-10-2008, 10:21 AM
Is this for a secondary or sub domain? In what directory have you placed the .htaccess file? The log indicates that it is located in /var/www/html.

The .htaccess code itself is fine and should work if you have everything set up correct of the domain. I ran some test and it appears as if you are correct that it is possible to hotlink to images on the domain indicated in your .htaccess file.

roadside
11-10-2008, 10:02 PM
The .htaccess file is located in the root directory of the main account (/var/www/html). I tried placing it in the images folder but that does not work there either. I tested the blocking with a hotlinking test site and find that the file is simply not working, even though the logs say it is working.

What could be wrong with the setup of my site? I contacted tech support but they insist that mod-rewrite is active. However, I'm not convinced it is working correctly or that something else isn't setup properly on the site.

Any other suggestions?

wildjokerdesign
11-11-2008, 06:43 AM
Is there anything else in the .htaccess file?