.htaccess mod_rewrite rule not working in Ubuntu - apache

My apologies if this is an easy one. I have Googled it up the hizzy to no avail.
I am running Ubuntu 9.04, Jaunty Jackelope and Apache2. After much trouble, I finally enabled mod_rewrite, and my .htaccess file is attempting to do it's thing, but is failing. This is my setup.
In /etc/apache2/conf.d/ I have a file called apeace-public-html.conf. It reads as follows:
# makes /home/apeace/public_html/ available through /localhost/apeace
Alias /apeace /home/apeace/public_html/
And in /home/apeace/public_html/ I have the following .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^test\.html$ index.html
Also in /home/apeace/public_html/ I have a file named index.html, but I do NOT have a file named test.html. It seems to me that this rewrite should show index.html when I try to access http://localhost/apeace/test.html. However, this is the error I get:
Not Found
The requested URL /home/apeace/public_html/index.html was not found on this server.
So the question is, what in the world am I doing wrong?
Much thanks.
-apeace

Just a guess here, but can you try to make the RewriteRule like ^test.html$ /apeace/index.html
From the error message, it seems it is translating `http://localhost/apeace/test.html to http://localhost/home/apeace/public_html/index.html

Your rewrite rule is working correctly since it's telling you it can't find "index.html". If you went to test.html and it said it can't find "test.html" then your rewrite rule would be at fault.
So what this means is that something else is wrong in your setup, whether it's a bad file or directory name somewhere, or whatever else. Make sure there's nothing basic you're overlooking.
But in answer to your question (especially the title), your htaccess is fine.

Related

Having Trouble with RewriteRule syntax and configuration, challenging

I'm really struggling with the syntax of a Rewrite Rule. I'm hoping you can help.
I used a node package module to create a bunch of html snapshots of a super ajaxy site. The module outputs the snapshots in a diretory named as the URL for later use with escape_fragment rewrite rules. So exampledomain.net/a45.php?lang=eng is output as ./snapshots/a45.php?lang=eng/index.html. So to cd into that directory I have to of course escape the special characters.
I am attempting to Rewrite http://testdomain.net/a45.php?lang=eng to http://testdomain.net/snapshots/a45.php?lang=eng/index.html and I cannot get my rewrite rules to work.
Here's the syntax I've tried:
in an .htaccess file in the subdirectory
Options +FollowSymLinks
RewriteEngine On
ReWriteBase /var/www/vhosts/testdomain.net/httpdocs/secure/clients/amg/3dot0
RewriteRule ^a45\.php?lang=eng$ /snapshots/a45.php?lang=eng/index.html
I have also tried it with and without RewriteBase.
I've also tried the same as above with the second url escaped and with a couple different characters on the first url ALL to no avail...
OH and I was sure to enable Allowoverride all on the entire httpdocs directory as well in the main vhost.conf file -- I know that directive is working becuase Options +Indexes allows me to browse directories throughout this tree.
Any advice or clues are appreciated greatly!
Directory names including characters ? = / are not going to be liked. Try to avoid them.
The purpose of a rewrite is to run another page from somewhere else, not dump something into a new directory. Is that what you're trying to do? You're telling the server than there is an index.html to run, in /snapshots/a45.php?lang=eng/ directory.
A RewriteRule isn't going to see the Query String anyway (?lang=eng). The ? is telling it that the p is optional.

How to use .htaccess to redirect missing files?

I've been hosting some files which aren't on the server anymore and apache error log keeps bugging me with the "file does not exist" line.
I'd like to use .htaccess to manually specify which files, if requested in the URI, should redirect to the root location (or any else, thereof).
Could anyone help me how to do that?
Example:
www.domain.com/non-existent-file.jpg should go to www.domain.com/
Solved it with:
RewriteRule non-existent-file.jpg http://www.domain.com/ [R=301]
Hope that's the best solution!

Rewrite not working

I am absolutely lost, trying anything silly. Probably you know the situation. I tried hints from many threads here and on Google as well, but nothing helped. I have rewrite module loaded on my Apache (checked by phpinfo). For a site I have .htaccess created, where currently simple rule is stored:
RewriteEngine on
RewriteBase /
RewriteRule ^/certifikaty\.html$ certifikaty.php
So, I expect http://www.contech.cz/certifikaty.html will show http://www.contech.cz/certifikaty.php. Unfortunatly not. So, I set in my httpd.conf these lines:
RewriteLogLevel 9
RewriteLog "logs/rewrite.log"
The file (rewrite.log) is created, but it's empty even after server restart.
Please, could you help me to get out of this?
Marek
I found the solution - I had directive AllowOveride None in my httpd.conf. It means all httpd.conf are ignored ....

How do I configure apache for a custom directory?

Trying to configure apache2 to load example.com/forum/ from a different document root, relative to the site root. Forums are installed somewhere else on the server.
Is there a directory alias command? I've found the alias configuration entry for apache, but had no luck.
Basically, I want example.com to have the same directory its always had, but example.com/forum/ to be hosted somewhere else, on the same server.
I tagged this question with mod_rewrite because I thought maybe it would be the key, here.
Cheers!
Alias is the right way, unless you have some subtlety that you didn't reveal in your question.
# http.conf
Alias /forum /usr/lib/bbs/ # or whatever
The job of Alias is to take the abstract URL coming into your system and map it to a concrete filesystem path. Once it has done that, the request is no longer an URL but a path. If there is no Alias or similar directive handling that URL, then it will get mapped to a conrete path via DocumentRoot.
If this isn't working, you have to debug it further. Are you getting errors when you access /forum? Look in the error log.
It all depends of what you want. You can "hardlink" with real path and it works (so you were right to think it could work with mod_rewrite).
Quick sample (that works on my production domains) to make an internal change (I add a subdirectory):
RewriteRule (.*) %{DOCUMENT_ROOT}/mysubfolder%{REQUEST_FILENAME} [QSA,L]
So you can easily do something like:
RewriteRule ^/forum/(.*) %{DOCUMENT_ROOT}/mysubfolder%{REQUEST_FILENAME} [QSA,L]
And my suggestion would be that if you plan to have more rewrite rules, keep everything homogeneous, i.e.: keep on using only rewrite rules, so use my suggestion above. This way you'll not get a bad mix of Alias, RewriteRules and so on. For nice and clean stuff: keep everything homogeneous.

htaccess rewrite question

I want to rewrite the url http://mydomain/myapp/fakefolder to http://mydomain/myapp/index.php
I tried the following rule but thats not working
RewriteEngine On
RewriteRule ^fakefolder$ index.php
The .htaccess file is located inside myapp.
Kindly help
Thanks
vineet
To begin with, your folder is not called vineetstore: it's called fakefolder.
The corrected rule works for me so I'd dare say your Apache installation is not configured to read .htaccess files in such location. You can easily test that: make a syntax error on purpose and see whether your site crashes.
Find your virtual host or site definition and make sure you have this directive:
AllowOverride All