# Apache rewrite not working?



## tony33 (Apr 21, 2017)

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:


```
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.


----------



## SirDice (Apr 21, 2017)

You can't have both installed:

```
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:

```
RewriteRule "/test/"  "/phpinfo.php" [R]
```
Note the '[R]' at the end, this tells it it should use a redirect.


----------



## tony33 (Apr 21, 2017)

SirDice said:


> You can't have both installed:
> 
> ```
> CONFLICTS_INSTALL=      caudium14-1.* \
> ...



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.


----------



## SirDice (Apr 21, 2017)

Check the bit about rewrite logging, that should help and will take a lot of the guesswork away: http://httpd.apache.org/docs/current/mod/mod_rewrite.html


----------



## tony33 (Apr 22, 2017)

SirDice said:


> You can't have both installed:
> 
> ```
> CONFLICTS_INSTALL=      caudium14-1.* \
> ...




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

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
	
	



```
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.


----------



## tony33 (Apr 23, 2017)

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.


----------



## Deleted member 9563 (Apr 23, 2017)

Did you change AllowOverride None to AllowOverride All in the default?


----------



## sidetone (Apr 23, 2017)

Did you clear the cache in that one browser?


----------

