Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following .htaccess file:

RewriteEngine   on
RewriteBase     /

RewriteRule     ^(/?)dir/?$            $1dir/subdir           [L]
RewriteRule     ^(/?)subdir2/?$        $1dir/subdir/subdir2   [L]

The redirecting works fine, if I type in the IP of the domain, but typing in the domainname/dir doesn't redirect me at all, instead shows me the content of the directory.

Another question: As I said, the redirecting with the IP works fine. However, although the 'R' flag is not set, the url changes in the url box. IP/dir changes into IP/dir/subdir. Why?

EDIT (11:20 GMT+1): Not quite sure if it's of any relevance, but before today the server didn't have a domain. I just bought a domain and set up all the nameserver pointing to the server up. Since I can access the page and it shows me the content of the /dir folder, I assume that I didn't mess up anything there.

EDIT (12:51 GMT+1): Output from apachectl -S:

apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
     default server (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost (/etc/apache2/sites-enabled/000-default:1)
Syntax OK

EDIT (19:26 GMT+1): Found the problem. The problem was that my server name was not set and I had duplicates in ports.conf and httpd.conf, both where "listening". Thanks for pointing out the "apachectl -S" command. One mysterious problem left: Why is the url changing, although no R flag is set. Forever a mystery...

share|improve this question
Neither of those rewrite rules will send a redirect response back to the client. You must have at least another rewrite rule somewhere else. – Ladadadada Feb 4 '12 at 10:30
Really? Well. That's the only .htaccess file I'm aware of. At least I haven't set any other redirecting, but as I said: ipaddress/dir redirects me to ipaddress/dir/subdir. – cherrun Feb 4 '12 at 11:12 is not a valid IP address; apache will never use this, however you tell it to. – adaptr Feb 6 '12 at 13:12
Uhm... yea, I don't know what I messed up. I played with the httpd.conf and apache.conf file. Now it doesn't give me the output anymore tho. But do you think it has something to do with my url problem? – cherrun Feb 6 '12 at 13:43
up vote 1 down vote accepted

You need to show more information; what does httpd -S output ?

Where are these rules placed ?

share|improve this answer
The bash console tells me that the httpd command was not found. The .htaccess file lies in /var/www – cherrun Feb 4 '12 at 11:13
On Debian-based systems, httpd is called apache2. It is usually located in /usr/sbin/ which is probably not in your $PATH unless you're root. Try apache2ctl -S instead. – Ladadadada Feb 4 '12 at 11:39
I edited my first post with the output. – cherrun Feb 4 '12 at 11:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.