Apache rewrite not working?

Hi, I have added to my apache 2.4 config files rewrite code to block hotlinking but it doesn't work. I then tried a very simple rewrite to redirect one path to another and that didn't work.

So, first off I need help on making sure mod_rewrite works. I checked via php info if the mod_rewrite was loaded and it is loaded.

Here's my first test code:

Code:
RewriteEngine On
RewriteRule "/test/"  "/phpinfo.php"

So, in our case I have https://example.com/test/ and it should redirect to https://example.com/phpinfo.php

However, the code posted above doesn't work. If I put the /test/ it just says no such directory found. That directory doesn't exist.

I am totally new to using the rewrite module. So, I want to make sure the code is correct.

I tried also adding ifmodule tags with and without them I still get the same results.

I ran a command for apache to check if the mod_rewrite was installed/loaded and it spit back out mod_rewrite.

So, I am pretty sure the module is installed and enabled.
I do have folders for apache24 and appache 22 and am not sure if apache22 is still installed on my machine. Let me know what command I can run to see if both apache24 and 22 are running and how I can delete apache22 without messing up my apache24.

Thanks for your time.
 
You can't have both installed:
Code:
CONFLICTS_INSTALL=      caudium14-1.* \
 	                apache-*-2.2.* apache22-*

What you're probably seeing are left-over configuration files in /usr/local/etc/apache22/.

I rarely use mod_rewrite but try this:
Code:
RewriteRule "/test/"  "/phpinfo.php" [R]
Note the '[R]' at the end, this tells it it should use a redirect.
 
You can't have both installed:
Code:
CONFLICTS_INSTALL=      caudium14-1.* \
                     apache-*-2.2.* apache22-*

What you're probably seeing are left-over configuration files in /usr/local/etc/apache22/.

You might be right. I use webmin to run and stop servers on my server. Webmin tells me apache 2.24.25 is runing. I checked both apache24 and apache22 config files. Just in case.

I have no clue why rewrite isn't working. I looked online for articles and ran command lines to check it and it shows that the modules are there. I check phpinfo and it shows it's there.

My assumption now is that either I am writing the rewrite code wrong or something with the setup is wrong meaning the config files I modified aren't being used or ran but I ruled this out since my other modifications like enabling ssl / https for my server works and other modification works. Which again those changes were made to apache24 config files and it work and I didn't modify the apache22 files with those changes. So, I am going to need help on how to debug the issue with mod_rewrite for Apache.
 
You can't have both installed:
Code:
CONFLICTS_INSTALL=      caudium14-1.* \
                     apache-*-2.2.* apache22-*

What you're probably seeing are left-over configuration files in /usr/local/etc/apache22/.

I rarely use mod_rewrite but try this:
Code:
RewriteRule "/test/"  "/phpinfo.php" [R]
Note the '[R]' at the end, this tells it it should use a redirect.


I checked the logs. I followed that webpage you gave me. I see no errors in the logs. Then I see you posted

code:
Code:
RewriteRule "/test/"  "/phpinfo.php" [R]

I then test it on my website and went to example.com/test/ and it redirected me to phpinfo.php

So, rewrite works. This confirms it works. However, I am still scratching my head as to why the anti-hotlinking isn't working.

Here's what I have:
code
Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://hpmouse.googlepages.com/hotlink.gif [NC,R,L]

This is supposed to prevent other websites from hotlinking my images. I used an online tester to test this and notice it's not working. The tester was still able to hotlink to my images.
 
I just tested it on multiple browsers and found the redirect works on google chrome, firefox, internet explorer, safari etc but there's one browser I use and was using when testing if the code works and this browser is specially designed. So, for some reason hotlinking code like a apache rewrite won't work on this browser and I don't know why.
 
Did you change AllowOverride None to AllowOverride All in the default?
 
Back
Top